#include<bits/stdc++.h>
using namespace std;
const int N=1e9+7;
using ll=unsigned long long;
bool a[N];
ll two_(string s){
return stoi(s,nullptr,2);
}
ll three_(string s){
return stoi(s,nullptr,3);
}
void twoA(string s){
char bt;
for(int i=1;i<=s.size()-1;i++){
bt=s[i];
if(s[i]=='0'){
s[i]='1';
a[two_(s)]=true;
}
else{
s[i]='0';
a[two_(s)]=true;
}
s[i]=bt;
}
}
ll threeA(string s){
char bt;
for(int i=0;i<=s.size()-1;i++){
bt=s[i];
if(s[i]=='0'){
s[i]='1';
if(a[three_(s)]==true) return three_(s);
s[i]='2';
if(a[three_(s)]==true) return three_(s);
}
else if(s[i]=='1'){
s[i]='0';
if(a[three_(s)]==true) return three_(s);
s[i]='2';
if(a[three_(s)]==true) return three_(s);
}
else{
s[i]='0';
if(a[three_(s)]==true) return three_(s);
s[i]='1';
if(a[three_(s)]==true) return three_(s);
}
s[i]=bt;
}
}
int main(){
string two,three;
cin>>two;
cin>>three;
twoA(two);
cout<<threeA(three);
return 0;
}