#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    p /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int d1, d2;
vector<int> arr;
long long DP[23][1 << 11][2];
long long dp(int i, int mask, bool less) {
  if (i == d2) return 1;
  if (mask == ((1 << 10) - 1)) return 0;
  if (DP[i][mask][less] != -1) return DP[i][mask][less];
  if (i < d1) {
    long long ans = 0;
    for (int next = 0; next < 7; next++) {
      if ((mask >> next) & 1) continue;
      if (less == false && next > arr[i]) continue;
      int newless = less | (next < arr[i]);
      int newmask = mask | (1 << next);
      if (i == d1 - 1) newless = false;
      ans += dp(i + 1, newmask, newless);
    }
    return DP[i][mask][less] = ans;
  } else {
    long long ans = 0;
    for (int next = 0; next < 7; next++) {
      if ((mask >> next) & 1) continue;
      if (less == false && next > arr[i]) continue;
      int newless = less | (next < arr[i]);
      int newmask = mask | (1 << next);
      if (i == d1 - 1) newless = false;
      ans += dp(i + 1, newmask, newless);
    }
    return DP[i][mask][less] = ans;
  }
  assert(0);
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  if (n == 1 && m == 1) {
    cout << "0";
    return 0;
  }
  vector<int> digs;
  if (n == 1)
    digs.push_back(0);
  else {
    n--;
    while (n) {
      digs.push_back(n % 7);
      n /= 7;
    }
  }
  reverse(digs.begin(), digs.end());
  d1 = digs.size();
  arr = digs;
  digs.clear();
  if (m == 1)
    digs.push_back(0);
  else {
    m--;
    while (m) {
      digs.push_back(m % 7);
      m /= 7;
    }
  }
  reverse(digs.begin(), digs.end());
  for (auto i : digs) arr.push_back(i);
  d2 = arr.size();
  if (d2 > 10) {
    cout << "0";
    return 0;
  }
  memset(DP, -1, sizeof(DP));
  cout << dp(0, 0, 0);
  return 0;
}
