#include <bits/stdc++.h>
using namespace std;
const long long int INF = (1ll << 60) - 1;
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int modulo(long long int a, long long int b) {
  long long int r = a % b;
  return r < 0 ? r + b : r;
}
unsigned long long int ncr(unsigned long long int n, unsigned long long int r) {
  if (r > n - r) r = n - r;
  unsigned long long int ans = 1;
  unsigned long long int i;
  for (i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }
  return ans;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void bfs(long long int node, vector<long long int> adj[], vector<bool> &visit,
         vector<long long int> &dis) {
  queue<long long int> q;
  visit[node] = true;
  dis[node] = 0;
  q.push(node);
  while (!q.empty()) {
    long long int s = q.front();
    q.pop();
    for (auto u : adj[s]) {
      if (visit[u]) continue;
      visit[u] = true;
      dis[u] = dis[s] + 1;
      q.push(u);
    }
  }
}
void NumNodesInSubTree(int s, int e, vector<long long int> adj[],
                       vector<long long int> &count1) {
  count1[s] = 1;
  for (auto u : adj[s]) {
    if (u == e) continue;
    NumNodesInSubTree(u, s, adj, count1);
    count1[s] += count1[u];
  }
}
class abc {
 public:
  long long int val;
  long long int ind;
};
bool fun1(abc x, abc y) {
  if (x.val == y.val) {
    return x.ind > y.ind;
  }
  return x.val > y.val;
}
string solve(long long int a) {
  string ret;
  while (a != 0) {
    long long int x = a % 3;
    char c;
    if (x == 0) c = '0';
    if (x == 1) c = '1';
    if (x == 2) c = '2';
    ret.push_back(c);
    a /= 3;
  }
  return ret;
}
long long int todeci(string ans) {
  reverse(ans.begin(), ans.end());
  long long int xx = 1;
  long long int ret = 0;
  for (long long int i = 0; i < ans.size(); i++) {
    long long int x = ans[i] - 48;
    ret += xx * x;
    xx *= 3;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int tc;
  tc = 1;
  while (tc--) {
    long long int a, c;
    cin >> a >> c;
    string aa, cc;
    aa = solve(a);
    cc = solve(c);
    if (aa.size() < cc.size()) {
      long long int sz = cc.size() - aa.size();
      while (sz--) aa.push_back('0');
    } else if (cc.size() < aa.size()) {
      long long int sz = aa.size() - cc.size();
      while (sz--) cc.push_back('0');
    }
    reverse(aa.begin(), aa.end());
    reverse(cc.begin(), cc.end());
    string ans;
    for (long long int i = 0; i < aa.size(); i++) {
      long long int x1 = aa[i] - 48;
      long long int x2 = cc[i] - 48;
      long long int x;
      if (x2 == 0) {
        x = (3 - x1) % 3;
      } else if (x2 == 1) {
        if (x1 == 0)
          x = 1;
        else if (x1 == 1)
          x = 0;
        else if (x1 == 2)
          x = 2;
      } else if (x2 == 2) {
        if (x1 == 0)
          x = 2;
        else if (x1 == 1)
          x = 1;
        else if (x1 == 2)
          x = 0;
      }
      ans.push_back(x + 48);
    }
    long long int fans = todeci(ans);
    cout << fans;
  }
}

### Prompt

Develop a solution in CPP to the problem described below:

Little Petya very much likes computers. Recently he has received a new "Ternatron IV" as a gift from his mother. Unlike other modern computers, "Ternatron IV" operates with ternary and not binary logic. Petya immediately wondered how the xor operation is performed on this computer (and whether there is anything like it).

It turned out that the operation does exist (however, it is called tor) and it works like this. Suppose that we need to calculate the value of the expression a tor b. Both numbers a and b are written in the ternary notation one under the other one (b under a). If they have a different number of digits, then leading zeroes are added to the shorter number until the lengths are the same. Then the numbers are summed together digit by digit. The result of summing each two digits is calculated modulo 3. Note that there is no carry between digits (i. e. during this operation the digits aren't transferred). For example: 1410 tor 5010 = 01123 tor 12123 = 10213 = 3410.

Petya wrote numbers a and c on a piece of paper. Help him find such number b, that a tor b = c. If there are several such numbers, print the smallest one.

Input

The first line contains two integers a and c (0 ≤ a, c ≤ 109). Both numbers are written in decimal notation.

Output

Print the single integer b, such that a tor b = c. If there are several possible numbers b, print the smallest one. You should print the number in decimal notation.

Examples

Input

14 34


Output

50


Input

50 34


Output

14


Input

387420489 225159023


Output

1000000001


Input

5 5


Output

0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int INF = (1ll << 60) - 1;
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int modulo(long long int a, long long int b) {
  long long int r = a % b;
  return r < 0 ? r + b : r;
}
unsigned long long int ncr(unsigned long long int n, unsigned long long int r) {
  if (r > n - r) r = n - r;
  unsigned long long int ans = 1;
  unsigned long long int i;
  for (i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }
  return ans;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void bfs(long long int node, vector<long long int> adj[], vector<bool> &visit,
         vector<long long int> &dis) {
  queue<long long int> q;
  visit[node] = true;
  dis[node] = 0;
  q.push(node);
  while (!q.empty()) {
    long long int s = q.front();
    q.pop();
    for (auto u : adj[s]) {
      if (visit[u]) continue;
      visit[u] = true;
      dis[u] = dis[s] + 1;
      q.push(u);
    }
  }
}
void NumNodesInSubTree(int s, int e, vector<long long int> adj[],
                       vector<long long int> &count1) {
  count1[s] = 1;
  for (auto u : adj[s]) {
    if (u == e) continue;
    NumNodesInSubTree(u, s, adj, count1);
    count1[s] += count1[u];
  }
}
class abc {
 public:
  long long int val;
  long long int ind;
};
bool fun1(abc x, abc y) {
  if (x.val == y.val) {
    return x.ind > y.ind;
  }
  return x.val > y.val;
}
string solve(long long int a) {
  string ret;
  while (a != 0) {
    long long int x = a % 3;
    char c;
    if (x == 0) c = '0';
    if (x == 1) c = '1';
    if (x == 2) c = '2';
    ret.push_back(c);
    a /= 3;
  }
  return ret;
}
long long int todeci(string ans) {
  reverse(ans.begin(), ans.end());
  long long int xx = 1;
  long long int ret = 0;
  for (long long int i = 0; i < ans.size(); i++) {
    long long int x = ans[i] - 48;
    ret += xx * x;
    xx *= 3;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int tc;
  tc = 1;
  while (tc--) {
    long long int a, c;
    cin >> a >> c;
    string aa, cc;
    aa = solve(a);
    cc = solve(c);
    if (aa.size() < cc.size()) {
      long long int sz = cc.size() - aa.size();
      while (sz--) aa.push_back('0');
    } else if (cc.size() < aa.size()) {
      long long int sz = aa.size() - cc.size();
      while (sz--) cc.push_back('0');
    }
    reverse(aa.begin(), aa.end());
    reverse(cc.begin(), cc.end());
    string ans;
    for (long long int i = 0; i < aa.size(); i++) {
      long long int x1 = aa[i] - 48;
      long long int x2 = cc[i] - 48;
      long long int x;
      if (x2 == 0) {
        x = (3 - x1) % 3;
      } else if (x2 == 1) {
        if (x1 == 0)
          x = 1;
        else if (x1 == 1)
          x = 0;
        else if (x1 == 2)
          x = 2;
      } else if (x2 == 2) {
        if (x1 == 0)
          x = 2;
        else if (x1 == 1)
          x = 1;
        else if (x1 == 2)
          x = 0;
      }
      ans.push_back(x + 48);
    }
    long long int fans = todeci(ans);
    cout << fans;
  }
}

```