#include <bits/stdc++.h>
using namespace std;
int l1, l2, l, ans, m, n;
void f(int pos, int a[], int b[]) {
  if (pos == l) {
    int i, j, k;
    j = 0;
    for (i = 0; i < l1; i++) j = j * 7 + b[i];
    k = 0;
    for (i; i < l; i++) k = k * 7 + b[i];
    if (j < n && k < m) ans++;
    return;
  }
  for (int i = 0; i < 7; i++) {
    if (a[i] == 0) {
      a[i] = 1;
      b[pos] = i;
      f(pos + 1, a, b);
      a[i] = 0;
    }
  }
}
int main() {
  int i, j, k, a[10], b[10];
  scanf("%d", &n);
  scanf("%d", &m);
  if (n == 1)
    l1 = 1;
  else {
    i = n - 1;
    l1 = 0;
    while (i != 0) {
      l1++;
      i /= 7;
    }
  }
  if (m == 1)
    l2 = 1;
  else {
    i = m - 1;
    l2 = 0;
    while (i != 0) {
      l2++;
      i /= 7;
    }
  }
  if (l1 + l2 > 7)
    printf("0\n");
  else {
    l = l1 + l2;
    ans = 0;
    for (i = 0; i < 7; i++) a[i] = b[i] = 0;
    f(0, a, b);
    printf("%d\n", ans);
  }
  return 0;
}
