#include<iostream>
#include<vector>
#include<stdlib.h>
#include<math.h>
using namespace std;
int main()
{
int x, y;
cin >> x >> y;
if (x < 0 || y < 0 || x > 1000000 || y > 1000000)
{
return (0);
}
if (x == y)
{
cout << x + 1 << endl;
return (0);
}
//if (x==1)
//{
//
cout << y + 1 << endl;
//
return (0);
//}
//if (y == 1)
//{
//
cout << y + 1 << endl;
//
return (0);
//}
if (x < y)
{
int temp = x;
x = y;
y = temp;
}
//fuction y=y0/x0*x
double a = y + 1;
double b = x + 1;
double coe = a / b;
int res = 0;
double flag1 = 0;
int flag = 0;
for (int i = 0; i <= x + 1; i++)
{
double temp1 = 0;
temp1 = coe*i;
int temp2 = (int)temp1;
if (fabs(temp1 - temp2) < 0.000001 || fabs(temp1 - temp2 - 1) < 0.000001)
{
flag = 1;
flag1 = temp1;
continue;
}
else
{
int temp3_top = int(temp1 + 1);
int temp3_bottom = int(temp1);
if (temp3_top > flag1 && temp3_top > temp1 )
{
if (flag == 1)
{
flag1 = temp1;
res += 2;
flag = 0;
continue;
}
else if (temp3_bottom > flag1 && temp1 > temp3_bottom)
{
flag1 = temp1;
res += 2;
flag = 0;
continue;
}
else
{
res += 1;
flag1 = temp1;
continue;
}
}
else
{
flag1 = temp1;
res += 2;
continue;
}
}
}
cout << res << endl;
return (0);
}