#include <iostream>
using namespace std;
int main ( ) {
	long long n,m,x = 1, y = 1,izhod = 0;
	bool downleft = false,downright = true, upleft = false,upright = false;
	cin >> n >> m;
	while (true){
		if (x < n && y == m && downright == true){
			izhod++;
			downright = false;
			downleft = true;
		}
		if (x == n && y < m && downleft == true){
			izhod++;
			downleft = false;
			upleft = true;
		}
		
		if (x < n && y == 1 && upleft == true){
			izhod++;
			upleft = false;
			upright = true;
		}
		if (x == 1 && y < m && upright == true){
			izhod++;
			upright = false;
			downright = true;
		}
		if (x <= n && y <= m){
			if (downright == true){
				x++;
				y++;
			}
			if (downleft == true){
				x++;
				y--;
			}
			if (upleft == true){
				x--;
				y--;
			}
			if (upright == true){
				x--;
				y++;
			}
		}
		if (x == 1 && y == 1 || x == n && y == 1 || x == 1 && y == m || x == n && y == m){
			break;
		}
	}
	cout << izhod + 1;
	return 0;
}
