#include <bits/stdc++.h>
using namespace std;
bool a[1005*1005];
int main()
{
int n,m;
while(cin>>n>>m)
{
if(n>m)swap(n,m);
memset(a,0,sizeof(a));
a[0]=1;
int notshow=0;
for(int i=n;i<=n*m;i++)
{
if(i>=m)
a[i]=a[i-n]||a[i-m];
else
a[i]=a[i-n];
if(a[i]==0)
notshow=max(notshow,i);
//printf("%d:%d\n",i,a[i]);
}
cout<<notshow<<endl;
}
}
using namespace std;
bool a[1005*1005];
int main()
{
int n,m;
while(cin>>n>>m)
{
if(n>m)swap(n,m);
memset(a,0,sizeof(a));
a[0]=1;
int notshow=0;
for(int i=n;i<=n*m;i++)
{
if(i>=m)
a[i]=a[i-n]||a[i-m];
else
a[i]=a[i-n];
if(a[i]==0)
notshow=max(notshow,i);
//printf("%d:%d\n",i,a[i]);
}
cout<<notshow<<endl;
}
}