#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m, ans;
int a, b;
int bin[20];
int cal(int n) {
  if (n == 0) return 1;
  long long tot = 1;
  for (int i = 1; tot <= n; i++) {
    if (tot * 7 > n) return i;
    tot *= 7;
  }
}
int st(int x, int d) {
  int s = 0;
  for (int i = 1; i <= d; i++, x /= 7) {
    if (s & bin[x % 7]) return -1;
    s |= bin[x % 7];
  }
  return s;
}
int main() {
  bin[0] = 1;
  for (int i = 1; i <= 10; i++) bin[i] = bin[i - 1] * 2;
  n = read();
  m = read();
  n--;
  m--;
  a = cal(n);
  b = cal(m);
  if (a + b > 7) {
    puts("0");
    return 0;
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++) {
      int s1 = st(i, a), s2 = st(j, b);
      if (s1 != -1 && s2 != -1 && (s1 & s2) == 0) ans++;
    }
  printf("%d\n", ans);
  return 0;
}
