#include <bits/stdc++.h>
using namespace std;
long long int A(int n, int k) {
  if (n < k) {
    return 0;
  }
  long long int res = 1;
  for (int i = n; i > n - k; --i) res *= i;
  return res;
}
int fact(int n) {
  int res = 1;
  for (int i = 2; i <= n; ++i) res *= i;
  return res;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  --n;
  --m;
  int dn = 0, dm = 0;
  int lastn = 0, lastm = 0;
  vector<int> dign, digm;
  if (n == 0) {
    dn = 1;
    dign.push_back(0);
  }
  if (m == 0) {
    dm = 1;
    digm.push_back(0);
  }
  while (n) {
    dn++;
    lastn = n % 7;
    dign.push_back(lastn);
    n /= 7;
  }
  while (m) {
    dm++;
    lastm = m % 7;
    digm.push_back(lastm);
    m /= 7;
  }
  reverse(dign.begin(), dign.end());
  reverse(digm.begin(), digm.end());
  if (dn + dm > 7) {
    cout << 0 << endl;
    return 0;
  }
  long long int ans = 0;
  int mask = 0;
  for (; mask < (1 << 7); ++mask) {
    vector<int> digits;
    for (int i = 0; i < 7; ++i) {
      if (mask & (1 << i)) {
        digits.push_back(i);
      }
    }
    if (digits.size() != dn + dm) continue;
    for (int i = 0; i < fact(dn + dm); ++i) {
      bool flag = 1;
      int j = 0;
      while (j < dn && digits[j] == dign[j]) ++j;
      if (j < dn && digits[j] > dign[j]) flag = 0;
      j = dn;
      while (j < dn + dm && digits[j] == digm[j - dn]) ++j;
      if (j < dn + dm && digits[j] > digm[j - dn]) flag = 0;
      if (flag) {
        ++ans;
      }
      next_permutation(digits.begin(), digits.end());
    }
  }
  cout << ans << endl;
  return 0;
}
