At the checkered field size m×n in the lower left corner is the dice. In one move, it can be rolled to the cage to the right or up. The path cost is the sum of the numbers on the top of the cube in all cells of the path (including the start and end).
Find the minimum cost path to the top right corner.
The first line of two positive integers m and n (1 ≤ m, n ≤ 1000) - the width and height of the board. The second row has three numbers from 1 to 6 - the number on the top, left, and the front face of the cube, respectively. Sum of numbers on opposite faces of the dice is 7, all the numbers on the faces of the cube is different.
Bring out the shortest possible path cost.