#include <bits/stdc++.h>
using namespace std;
template <typename T>
T nCr(T n, T r) {
  if (r > n - r) r = n - r;
  int ans = 1, i;
  for (i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }
  return ans;
}
template <typename T, typename T2>
T2 power(T x, T y) {
  if (y == 0) return 1;
  T2 res = power(x, y / 2);
  if (y % 2) return res * res * x;
  return res * res;
}
long long modularExponentiation(long long x, long long n, long long M) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % M, n / 2, M);
  return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M;
}
long long binaryExponentiation(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return binaryExponentiation(x * x, n / 2);
  else
    return x * binaryExponentiation(x * x, (n - 1) / 2);
}
long long GCD(long long A, long long B) {
  if (B == 0)
    return A;
  else
    return GCD(B, A % B);
}
long long extended_GCD(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = extended_GCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
long long modinv(long long a, long long mod) {
  long long x, y;
  extended_GCD(a, mod, x, y);
  if (x < 0) x += mod;
  return x;
}
long long modPrimeInverse(long long A, long long M) {
  return modularExponentiation(A, M - 2, M);
}
void sieve(long long N) {
  bool isPrime[N + !1];
  for (long long i = 0; i <= N; ++i) {
    isPrime[i] = true;
  }
  isPrime[0] = false;
  isPrime[1] = false;
  for (long long i = 2; i * i <= N; ++i) {
    if (isPrime[i] == true) {
      for (long long j = i * i; j <= N; j += i) isPrime[j] = false;
    }
  }
}
long long minPrime[1000007];
void factorSieve(long long n) {
  memset(minPrime, 0, sizeof(minPrime));
  for (long long i = 2; i * i <= n; ++i) {
    if (minPrime[i] == 0) {
      for (long long j = i * i; j <= n; j += i) {
        if (minPrime[j] == 0) {
          minPrime[j] = i;
        }
      }
    }
  }
  for (long long i = 2; i <= n; ++i) {
    if (minPrime[i] == 0) {
      minPrime[i] = i;
    }
  }
}
long long factorize(long long n) {
  map<long long, long long> m;
  m.clear();
  while (n != 1) {
    m[minPrime[n]]++;
    n /= minPrime[n];
  }
  for (auto i : m) {
    if (i.second > 1) {
      return 0;
    }
  }
  return 1;
}
void merge(long long A[], long long start, long long mid, long long end) {
  long long p = start, q = mid + 1;
  long long Arr[end - start + 1], k = 0;
  for (long long i = start; i <= end; i++) {
    if (p > mid)
      Arr[k++] = A[q++];
    else if (q > end)
      Arr[k++] = A[p++];
    else if (A[p] < A[q])
      Arr[k++] = A[p++];
    else
      Arr[k++] = A[q++];
  }
  for (long long p = 0; p < k; p++) {
    A[start++] = Arr[p];
  }
}
void merge_sort(long long A[], long long start, long long end) {
  if (start < end) {
    long long mid = (start + end) / 2;
    merge_sort(A, start, mid);
    merge_sort(A, mid + 1, end);
    merge(A, start, mid, end);
  }
}
long long binarySearch(long long a[], long long low, long long high,
                       long long key) {
  while (low <= high) {
    long long mid = (low + high) / 2;
    if (a[mid] < key) {
      low = mid + 1;
    } else if (a[mid] > key) {
      high = mid - 1;
    } else {
      return mid;
    }
  }
  return -1;
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  if (a.first == b.first) {
    a.second > b.second;
  }
  return (a.first < b.first);
}
string itot(long long n) {
  string s = "";
  while (n / 3) {
    s += to_string(n % 3);
    n /= 3;
  }
  s += to_string(n % 3);
  reverse(s.begin(), s.end());
  return s;
}
void solve() {
  long long a, c;
  cin >> a >> c;
  string sa = itot(a);
  string sc = itot(c);
  string zero = "";
  if (sa.length() > sc.length()) {
    for (int i = 1; i <= (sa.length() - sc.length()); i++) zero += '0';
    zero += sc;
    sc = zero;
  } else {
    for (int i = 1; i <= (sc.length() - sa.length()); i++) zero += '0';
    zero += sa;
    sa = zero;
  }
  string ans = "";
  for (int i = 0; i < sa.length(); i++) {
    long long diff = (sa[i] - '0') - (sc[i] - '0');
    if (diff < 0) diff += 3;
    ans += to_string((3 - diff) % 3);
  }
  long long val = 0;
  for (int i = 0; i < sa.length(); i++) {
    val += (ans[i] - '0') * (pow(3, (sa.length() - 1 - i)));
  }
  cout << val;
}
int main() {
  ;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

### Prompt

Your task is to create a CPP solution to the following problem:

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;
template <typename T>
T nCr(T n, T r) {
  if (r > n - r) r = n - r;
  int ans = 1, i;
  for (i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }
  return ans;
}
template <typename T, typename T2>
T2 power(T x, T y) {
  if (y == 0) return 1;
  T2 res = power(x, y / 2);
  if (y % 2) return res * res * x;
  return res * res;
}
long long modularExponentiation(long long x, long long n, long long M) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modularExponentiation((x * x) % M, n / 2, M);
  return (x * modularExponentiation((x * x) % M, (n - 1) / 2, M)) % M;
}
long long binaryExponentiation(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return binaryExponentiation(x * x, n / 2);
  else
    return x * binaryExponentiation(x * x, (n - 1) / 2);
}
long long GCD(long long A, long long B) {
  if (B == 0)
    return A;
  else
    return GCD(B, A % B);
}
long long extended_GCD(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = extended_GCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
long long modinv(long long a, long long mod) {
  long long x, y;
  extended_GCD(a, mod, x, y);
  if (x < 0) x += mod;
  return x;
}
long long modPrimeInverse(long long A, long long M) {
  return modularExponentiation(A, M - 2, M);
}
void sieve(long long N) {
  bool isPrime[N + !1];
  for (long long i = 0; i <= N; ++i) {
    isPrime[i] = true;
  }
  isPrime[0] = false;
  isPrime[1] = false;
  for (long long i = 2; i * i <= N; ++i) {
    if (isPrime[i] == true) {
      for (long long j = i * i; j <= N; j += i) isPrime[j] = false;
    }
  }
}
long long minPrime[1000007];
void factorSieve(long long n) {
  memset(minPrime, 0, sizeof(minPrime));
  for (long long i = 2; i * i <= n; ++i) {
    if (minPrime[i] == 0) {
      for (long long j = i * i; j <= n; j += i) {
        if (minPrime[j] == 0) {
          minPrime[j] = i;
        }
      }
    }
  }
  for (long long i = 2; i <= n; ++i) {
    if (minPrime[i] == 0) {
      minPrime[i] = i;
    }
  }
}
long long factorize(long long n) {
  map<long long, long long> m;
  m.clear();
  while (n != 1) {
    m[minPrime[n]]++;
    n /= minPrime[n];
  }
  for (auto i : m) {
    if (i.second > 1) {
      return 0;
    }
  }
  return 1;
}
void merge(long long A[], long long start, long long mid, long long end) {
  long long p = start, q = mid + 1;
  long long Arr[end - start + 1], k = 0;
  for (long long i = start; i <= end; i++) {
    if (p > mid)
      Arr[k++] = A[q++];
    else if (q > end)
      Arr[k++] = A[p++];
    else if (A[p] < A[q])
      Arr[k++] = A[p++];
    else
      Arr[k++] = A[q++];
  }
  for (long long p = 0; p < k; p++) {
    A[start++] = Arr[p];
  }
}
void merge_sort(long long A[], long long start, long long end) {
  if (start < end) {
    long long mid = (start + end) / 2;
    merge_sort(A, start, mid);
    merge_sort(A, mid + 1, end);
    merge(A, start, mid, end);
  }
}
long long binarySearch(long long a[], long long low, long long high,
                       long long key) {
  while (low <= high) {
    long long mid = (low + high) / 2;
    if (a[mid] < key) {
      low = mid + 1;
    } else if (a[mid] > key) {
      high = mid - 1;
    } else {
      return mid;
    }
  }
  return -1;
}
bool sortbysec(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  if (a.first == b.first) {
    a.second > b.second;
  }
  return (a.first < b.first);
}
string itot(long long n) {
  string s = "";
  while (n / 3) {
    s += to_string(n % 3);
    n /= 3;
  }
  s += to_string(n % 3);
  reverse(s.begin(), s.end());
  return s;
}
void solve() {
  long long a, c;
  cin >> a >> c;
  string sa = itot(a);
  string sc = itot(c);
  string zero = "";
  if (sa.length() > sc.length()) {
    for (int i = 1; i <= (sa.length() - sc.length()); i++) zero += '0';
    zero += sc;
    sc = zero;
  } else {
    for (int i = 1; i <= (sc.length() - sa.length()); i++) zero += '0';
    zero += sa;
    sa = zero;
  }
  string ans = "";
  for (int i = 0; i < sa.length(); i++) {
    long long diff = (sa[i] - '0') - (sc[i] - '0');
    if (diff < 0) diff += 3;
    ans += to_string((3 - diff) % 3);
  }
  long long val = 0;
  for (int i = 0; i < sa.length(); i++) {
    val += (ans[i] - '0') * (pow(3, (sa.length() - 1 - i)));
  }
  cout << val;
}
int main() {
  ;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```