#include <iostream>
using namespace std;

int Width,Height;
bool isCorner(int x, int y)
{
	return (x==0 && y==0) ||
		   (x==Width-1 && y==0) ||
		   (x==0 && y==Height-1) ||
		   (x==Width-1 && y==Height-1); 
}

int main()
{
	cin >> Height >> Width;
	
	int x=1,y=1;
	int dx=1,dy=1;
	int countOfHits=0;
	while (!isCorner(x,y))
	{
		if (x==0 || x==Width-1) {dx=-dx;++countOfHits;}
		if (y==0 || y==Height-1) {dy=-dy;++countOfHits;}
		x+=dx;
		y+=dy;
	}
	cout << countOfHits+1;
	
	cout << "\n";
	return 0;
}
