#include<iostream>
using namespace std;
int main(){
	int n,m,sx=1,sy=1,mx=1,my=1,udari=0,pomalko;
	cin>>n>>m;
	if (n!=m){
		while (!(mx==0 and my==0) and !(mx==m-1 and my==0) and !(mx==0 and my==n-1) and !(mx==m-1 and my==n-1)){
			if (sx==1 and sy==1){
				if (n-my<m-mx){
					pomalko=n-my;
				}else{
					pomalko=m-mx;
				}
				mx+=pomalko-1;
				my+=pomalko-1;
				udari++;
				if(my==n-1){
					sy=-1;
				}else{
					sx=-1;
				}
				continue;
			}
			if (sx==-1 and sy==1){
				if (n-my<mx+1){
					pomalko=n-my;
				}else{
					pomalko=mx+1;
				}
				mx-=pomalko-1;
				my+=pomalko-1;
				udari++;
				if(my==n-1){
					sy=-1;
				}else{
					sx=1;
				}
				continue;
			}
			if (sx==-1 and sy==-1){
				if (my+1<mx+1){
					pomalko=my+1;
				}else{
					pomalko=mx+1;
				}
				mx-=pomalko-1;
				my-=pomalko-1;
				udari++;
				if (my==0){
					sy=1;
				}else{
					sx=1;
				}
				continue;
			}
			if (sx==1 and sy==-1){
				if (my+1<m-mx){
					pomalko=my+1;
				}else{
					pomalko=m-mx;
				}
				mx+=pomalko-1;
				my-=pomalko-1;
				udari++;
				if (mx==m-1){
					sx=-1;
				}else{
					sy=1;
				}
				continue;
			}
		}
	}else{
		udari=1;
	}
	cout<<udari<<endl;
	return 0;
}
