#include <bits/stdc++.h>
using namespace std;
const int N = 15, M = 1 << 7;
int f[N][M][2], c[N], d[N], y, x, n, m, f2[N][M][2];
int cnt[M];
int dp(int x, int s, int lim) {
  if (x == 0) return 1;
  int &ans = f[x][s][lim];
  if (ans != -1) return ans;
  ans = 0;
  int r = lim ? c[x] : 6;
  for (int i = 0; i <= r; i++) {
    if (!(s >> i & 1)) {
      ans += dp(x - 1, s | (1 << i), lim && (i == r));
    }
  }
  return ans;
}
int dp2(int x, int s, int lim) {
  if (x == 0) return 1;
  int &ans = f2[x][s][lim];
  if (ans != -1) return ans;
  ans = 0;
  int r = lim ? d[x] : 6;
  for (int i = 0; i <= r; i++) {
    if (!(s >> i & 1)) {
      ans += dp2(x - 1, s | (1 << i), lim && (i == r));
    }
  }
  return ans;
}
int main() {
  memset(f, -1, sizeof(f));
  memset(f2, -1, sizeof(f2));
  cin >> n >> m;
  n--;
  m--;
  x = y = 0;
  if (!n) x = 1;
  if (!m) y = 1;
  while (n) c[++x] = n % 7, n /= 7;
  while (m) d[++y] = m % 7, m /= 7;
  if (x + y > 7) {
    puts("0");
    return 0;
  }
  for (int j = 0; j < M; j++) {
    for (int i = 0; i < 7; i++)
      if (!(j >> i & 1)) ++cnt[j];
  }
  long long ans = 0;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if ((i | j) != M - 1) continue;
      if (cnt[i] == x && cnt[j] == y) ans += dp(x, i, 1) * dp2(y, j, 1);
    }
  }
  cout << ans << endl;
}
