Dice#1861

Dice

1 second
256 megabytes
Easy

On a checkered field of size m \times n, a die is placed in the lower left corner. In one move, the die can be rolled to the cell to the right or up. The cost of a path is defined as the sum of the numbers on the top face of the die for all cells in the path (including the start and end positions).

Find the minimum possible cost of a path to the upper right corner.

Input

The first line contains two natural numbers and (1 \leq m, n \leq 1000) — the width and height of the board. The second line contains three numbers from to — the numbers on the top, left, and front faces of the die, respectively. The sum of the numbers on opposite faces of the die is , and all numbers on the faces of the die are distinct.

Output

Print the minimum possible cost of a path.

Examples

Example 1

Loading
Loading