#include<cstdio>
using namespace std;
int main(void)
{
	int x,y,cnt,ans,i;
	double a,b,c;
	scanf("%d %d",&x,&y);
	cnt=2;
	a=(double)x/y;
	b=(double)y/x;
	for(i=1;i<y;i++){
		c=x*i%y;
		if(c==0){
			cnt++;
		}
	}
	ans=(x+1+y+1)-cnt;
	printf("%d\n",ans);
	return 0;
}
