#include <bits/stdc++.h>
int n, m, kn, km;
int date[7];
bool num[7];
int ans;
int convert7to10(int* begin, int* end) {
  int num = 0;
  while (begin < end) {
    num = num * 7 + *begin;
    ++begin;
  }
  return num;
}
bool check() {
  if (convert7to10(date, date + kn) < n) {
    if (convert7to10(date + kn, date + kn + km) < m) return true;
  }
  return false;
}
void rec(int i, int pos) {
  date[pos] = i;
  if (pos + 1 == kn + km) {
    if (check()) ++ans;
    return;
  }
  for (int it = 0; it < 7; ++it) {
    if (!num[it]) {
      num[it] = true;
      rec(it, pos + 1);
      num[it] = false;
    }
  }
}
void solution() {
  scanf("%d%d", &n, &m);
  for (int it = 1; pow(7, it - 1) < n; ++it) kn = it;
  for (int it = 1; pow(7, it - 1) < m; ++it) km = it;
  if (kn == 0) kn = 1;
  if (km == 0) km = 1;
  if (kn + km > 7) {
    printf("0");
    return;
  }
  for (int it = 0; it < 7; ++it) {
    if (!num[it]) {
      num[it] = true;
      rec(it, 0);
      num[it] = false;
    }
  }
  printf("%d", ans);
}
int main() {
  solution();
  return 0;
}
