#include <bits/stdc++.h>
using namespace std;
long long int f[2][1 << 7][2];
long long int g[2][1 << 7][2];
string itos(int v) {
  if (v == 0) return "0";
  string ans = "";
  for (; v != 0; v /= 7) ans = string(1, '0' + (v % 7)) + ans;
  return ans;
}
int solve(string s, long long int dp[2][1 << 7][2]) {
  int n = s.size();
  int rw = 0;
  dp[rw][0][0] = 1;
  dp[rw][0][1] = 1;
  for (int i = n - 1; i >= 0; i--) {
    rw ^= 1;
    for (int b = 0; b < (1 << 7); b++) {
      for (int e = 0; e < 2; e++) {
        dp[rw][b][e] = 0;
        for (int j = 0; j < 7; j++)
          if (b & (1 << j)) {
            if (e == 1 && j + '0' > s[i]) continue;
            int ne = e;
            if (j + '0' != s[i]) ne = 0;
            dp[rw][b][e] += dp[rw ^ 1][b ^ (1 << j)][ne];
          }
      }
    }
  }
  return rw;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  string sn = itos(n - 1);
  int rf = solve(sn, f);
  string sm = itos(m - 1);
  int rg = solve(sm, g);
  long long int ans = 0;
  for (int a = 0; a < (1 << 7); a++)
    if (__builtin_popcount(a) == sn.size()) {
      for (int b = 0; b < (1 << 7); b++)
        if (__builtin_popcount(b) == sm.size()) {
          bool ok = true;
          for (int i = 0; i < 7 && ok; i++) {
            if (a & (1 << i))
              if (b & (1 << i)) ok = false;
          }
          if (!ok) continue;
          ans += f[rf][a][1] * g[rg][b][1];
        }
    }
  printf("%lld\n", ans);
  return 0;
}
