#include <bits/stdc++.h>
int n, m;
int a[10], b[10], lena, lenb;
int f[10][1 << 7], g[10][1 << 7];
int dfs(int p, int up, int st, int x) {
  if (!p) return 1;
  if (x == 0) {
    up = 1;
    x = -1;
  }
  if (!up && g[p][st]) return f[p][st];
  int stop = 6, temp = 0;
  if (x > 0) {
    if (up) stop = a[x];
    for (int i = 0; i <= stop; i++)
      if (!((st >> i) & 1))
        temp += dfs(p - 1, up && (i == stop), st | (1 << i), x - 1);
  } else {
    if (up) stop = b[p];
    for (int i = 0; i <= stop; i++)
      if (!((st >> i) & 1))
        temp += dfs(p - 1, up && (i == stop), st | (1 << i), x);
  }
  if (!up) {
    g[p][st] = 1;
    f[p][st] = temp;
  }
  return temp;
}
void Solve() {
  n--;
  m--;
  for (int i = n; i; i /= 7) a[++lena] = i % 7;
  for (int i = m; i; i /= 7) b[++lenb] = i % 7;
  if (!n) lena++;
  if (!m) lenb++;
  if (lena + lenb > 7) {
    printf("0\n");
    return;
  }
  printf("%d\n", dfs(lena + lenb, 1, 0, lena));
}
int main() {
  scanf("%d%d", &n, &m);
  if (n >= 823544 || m >= 823544) {
    printf("0\n");
    return 0;
  }
  Solve();
  return 0;
}
