Bishops on a Toral Board#5669

Bishops on a Toral Board

1 second
64 megabytes
Easy

A bishop is a chess piece that can move in any diagonal direction to any number of cells.

Imagine that we take a board of a size m \times n and connect its top and bottom edges, and its left and right edges, so that it would have a form of a torus. For example, on a 7 \times 10 board the neighbours of a cell would be , , , , , , , ; the neighbours of a cell - , , , , , , , .

On a toral board chess pieces are no longer limited with the edges, and, for example, on a 7 \times 10 board a bishop from any cell can move to any other cell of the board in one turn, say, from cell to cell by a path → → .

Let us say that a set of bishops covers the board if one can move some bishop to any free cell in one turn. In other words, each cell is either occupied or threatened by some bishop.

Your task is to find out what is the minimal number of bishops one needs to cover the m \times n toral board.

Input

Input file contains and separated by a space (1 \le n, m \le 10^{100}).

Output

Output the minimal number of bishops needed to cover the m \times n toral board.

Examples

Example 1

Loading
Loading