#include<bits/stdc++.h>
using namespace std;
#define int long long
int l1,l2;
string n,m,a,b,c;
signed main() {
cin >> n >> m;
l1 = n.size();
l2 = m.size();
for(int i = 0;i<l1;i++) {
int num = 0,t = 1,res;
a = n;
if(n[i] == '0') {
a[i] = '1';
}else {
a[i] = '0';
}
for(int j = l1-1;j>=0;j--,t*=2) {
num += (a[j] - '0') * t;
}
b = "";
res = num;
while(num != 0) {
b += (num % 3) + '0';
num /= 3;
}
for(int i = 0;i<l2;i++) {
c[l2 - 1 - i] = b[i];
}
int cnt = 0;
for(int i = 0;i<l2;i++) {
if(b[i] != m[l2-i-1]) {
cnt++;
}
}
if(cnt == 1) {
cout << res;
return 0;
}
}
return 0;
}