#include <iostream>
using namespace std;

int n, m, output, bx, by, dx = 1, dy = 1;
bool started, a;

bool inCorner()
{
	if( (bx == 0 && by == 0) ||
		(bx == n - 1 && by == 0) ||
		(bx == 0 && by == m - 1) ||
		(bx == n - 1 && by == m - 1)
		)
		{ return true; }
		
	return false;
}

int main()
{
	cin >> n >> m;
	while(!inCorner() || !started)
	{
		started = true; a = false;
		bx += dx;
		by += dy;
		
		if(bx <= 0 || bx >= n - 1)
		{
			dx = -dx;
			output ++;
			a = true;
		}
		
		if(by <= 0 || by >= m - 1)
		{
			dy = -dy;
			if(!a)
			{
				output ++;
			}
		}
	}
	cout << output << endl;
	return 0;
}
