BISHOP2 - Chessboard Billiard

Let's imagine: there is a chess piece billiard ball. Its movements resemble the ones of a bishop chess piece. The only difference is that when a billiard ball hits the board's border, it can reflect from it and continue moving.

More formally, first one of four diagonal directions is chosen and the billiard ball moves in that direction. When it reaches the square located on the board's edge, the billiard ball reflects from it; it changes the direction of its movement by 90 degrees and continues moving. Specifically, having reached a corner square, the billiard ball is reflected twice and starts to move the opposite way. While it moves, the billiard ball can make an infinite number of reflections. At any square of its trajectory the billiard ball can stop and on that the move is considered completed.

It is considered that one billiard ball a beats another billiard ball b if a can reach a point where b is located.

You are suggested to find the maximal number of billiard balls, that pairwise do not beat each other and that can be positioned on a chessboard n × m in size.

Input

The first line of input contains two integers n and m (2 ≤ n, m ≤ 106).

Output

Print a single line for each input line containing a single number, the maximum possible number of billiard balls that do not pairwise beat each other.

Example

Input:
3 4
2 2
5 5

Output:
2
2
5

ID RESULT TIME
code...



Added by:Bidhan
Date:2011-06-15
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 FSHARP FORTRAN HASK PYTHON PYTHON3
Resource:Codeforces Beta Round

hide comments
2013-01-27 23:01:06 Santiago Palacio
There are inputs where n or m = 1, i have tested that. Nice problem.

Last edit: 2013-01-28 04:43:47
2011-09-23 12:14:51 blashyrkh
Please explain result for n,m=3,4. Why 2? Where these billiard balls can be placed?

Edit: understood. These balls can be placed in (0,0) and (0,3)

Last edit: 2011-09-23 12:17:02
2011-06-30 19:41:18 Efim
how many lines are in input?
2011-06-16 13:25:05 Alex Anderson
The example input of 1 1 and 1 2 is contradictory to the specifications.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.