#include <bits/stdc++.h>
using namespace std;
int n, m, dn = 1, dm = 1;
int ans = 0;
void bf(int x, int p, int v, int mask) {
  if (x == 0 && p == dn) {
    if (v >= n) return;
    bf(1, 0, 0, mask);
    return;
  }
  if (x == 1 && p == dm) {
    if (v >= m) return;
    ++ans;
    return;
  }
  for (int i = 0; i < 7; ++i) {
    if (!(mask & (1 << i))) {
      bf(x, p + 1, v * 7 + i, mask | (1 << i));
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  if (n > 1) dn += (int)floor(log(n - 1) / log(7));
  if (m > 1) dm += (int)floor(log(m - 1) / log(7));
  if (dn + dm > 7)
    printf("0\n");
  else {
    bf(0, 0, 0, 0);
    printf("%d\n", ans);
  }
  return 0;
}
