#include<iostream>
using namespace std;
int main()
{
	int n,m,x=0,y=0,xPos=1,yPos=1,puti=0;
	cin>>n>>m;
	if(n==m)
	{
		cout<<"1";
		return 0;
	}
	while(true)
	{
		x+=xPos;
		y+=yPos;
		if((x==0 and y==0) or (x==m-1 and y==0) or (x==0 and y==n-1) or (x==m-1 and y==n-1))
		{
			cout<<puti+1;
			return 0;
		}
		if(x==0 or x==m-1)
		{
			xPos*=-1;
			puti++;
			continue;
		}
		if(y==0 or y==n-1)
		{
			yPos*=-1;
			puti++;
			continue;
		}
	}
	return 0;
}
