#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long LL;
const int M=10010;
struct BIG{
int l;
int num[M];
BIG(){
l=1;
num[1]=0;
}
void set(long long n){
l=0;
if(n==0){l=1;num[1]=0;}
while(n>0){
l++;
num[l]=n%10;
n/=10;
}
}
void set(string s){
l=s.size();
for(int i=1;i<=l;i++)
num[i]=s[l-i]-'0';
}
void print(){
for(int i=l;i>=1;i--) cout<<num[i];
}
};
bool operator<(const BIG &a,const BIG &b){
if(a.l!=b.l) return a.l<b.l;
for(int i=a.l;i>=1;i--)
if(a.num[i]!=b.num[i]) return a.num[i]<b.num[i];
return false;
}
bool operator>(const BIG &a,const BIG &b){return b<a;}
bool operator==(const BIG &a,const BIG &b){return !(b<a)&&!(a<b);}
bool operator!=(const BIG &a,const BIG &b){return b<a||a<b;}
bool operator<=(const BIG &a,const BIG &b){return !(b<a);}
bool operator>=(const BIG &a,const BIG &b){return !(a<b);}
BIG operator+(const BIG &a,const BIG &b){
BIG c;
c.l=max(a.l,b.l);
int u=0;
for(int i=1;i<=c.l;i++){
int t=u;
if(i<=a.l) t+=a.num[i];
if(i<=b.l) t+=b.num[i];
c.num[i]=t%10;
u=t/10;
}
if(u>0){
c.l++;
c.num[c.l]=u;
}
return c;
}
BIG operator-(const BIG &a,const BIG &b){
BIG c;
c.l=max(a.l,b.l);
int u=0;
for(int i=1;i<=c.l;i++){
int t=a.num[i]-u;
if(i<=b.l) t-=b.num[i];
if(t<0){
c.num[i]=t+10;
u=1;
}
else{
c.num[i]=t;
u=0;
}
}
while(u>0){
c.l++;
c.num[c.l]=u%10;
u/=10;
}
return c;
}
BIG operator*(const BIG &a,const int &b){
BIG c;
c.l=a.l;
long long u=0;
for(int i=1;i<=c.l;i++){
long long t=1ll*a.num[i]*b+u;
c.num[i]=t%10;
u=t/10;
}
while(u>0){
c.l++;
c.num[c.l]=u%10;
u/=10;
}
return c;
}
BIG operator/(const BIG &a,const int &b){
BIG c;
c.l=a.l;
long long r=0;
for(int i=c.l;i>=1;i--){
long long t=r*10+a.num[i];
c.num[i]=t/b;
r=t%b;
}
while(c.num[c.l]==0&&c.l>1) c.l--;
return c;
}
BIG a,b;
string s1,s2;
int main(){
cin >> s1 >> s2;
a.set(s1);
b.set(s2);
int cnt = 0;
while (a.num[1]%2==0 && b.num[1]%2==0){
cnt++;
a = a / 2;
b = b / 2;
}
while (true){
while (a.num[1]%2==0)
a = a / 2;
while (b.num[1]%2==0)
b = b / 2;
if (a < b)
swap(a, b);
a = a - b;
if (a.num[1]==0&&a.l==1)
break;
}
for(int i=1;i<=cnt;i++) b=b*2;
b.print();
return 0;
}