#include <bits/stdc++.h>
using namespace std;
long long lgn, lgm, tot, numberh = 0, numbermin = 0;
long long n, m, put7[30];
long long luat[10];
long long cif[10];
long long maxpower(long long x) {
  if (x == 0) return 1;
  int start = 0, tot = 0;
  while (tot < x) {
    if (start == 8) return 7;
    tot = put7[start] * 7 - 1;
    start++;
  }
  return start;
}
void back(long long poz) {
  if (poz > lgn + lgm) {
    tot++;
  } else {
    for (long long i = 0; i <= 6; i++) {
      if (luat[i] == 0) {
        luat[i] = 1;
        cif[poz] = i;
        if (poz <= lgn) {
          numberh = numberh + i * put7[lgn - poz];
        } else {
          numbermin = numbermin + i * put7[lgm - (poz - lgn)];
        }
        if (numberh < n && numbermin < m) back(poz + 1);
        if (poz <= lgn) {
          numberh = numberh - i * put7[lgn - poz];
        } else {
          numbermin = numbermin - i * put7[lgm - (poz - lgn)];
        }
        luat[i] = 0;
        cif[poz] = 0;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  put7[0] = 1;
  for (long long i = 1; i <= 7; i++) {
    put7[i] = put7[i - 1] * 7;
  }
  lgn = maxpower(n - 1);
  lgm = maxpower(m - 1);
  if (lgn + lgm > 7)
    cout << 0 << '\n';
  else {
    back(1);
    cout << tot << '\n';
  }
  return 0;
}
