#include <bits/stdc++.h>
using namespace std;
int fac(int n) {
  int s = 1;
  for (int i = 2; i <= n; i++) s *= i;
  return s;
}
int c(int n, int k) { return fac(n) / fac(n - k) / fac(k); }
multiset<int> getSet(int n, int k) {
  multiset<int> m;
  for (int i = 0; i < (k); i++) {
    m.insert(n % 7);
    n = n / 7;
  }
  return m;
}
bool isSame(multiset<int>& m) {
  for (int i = 0; i < 10; i++)
    if (m.count(i) > 1) return true;
  return false;
}
int main() {
  long long n, m;
  cin >> n >> m;
  int nk = 0, mk = 0;
  int t = n - 1;
  while (t) {
    nk++;
    t /= 7;
  }
  t = m - 1;
  while (t) {
    mk++;
    t /= 7;
  }
  if (n == 1) nk = 1;
  if (m == 1) mk = 1;
  long long s = 0;
  int np = (n - 1) / pow(7, nk - 1);
  int mp = (m - 1) / pow(7, mk - 1);
  if (nk + mk > 7) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    multiset<int> nm = getSet(i, nk);
    if (!isSame(nm))
      for (int j = 0; j < m; j++) {
        multiset<int> mm = getSet(j, mk);
        mm.insert(nm.begin(), nm.end());
        if (!isSame(mm)) {
          s++;
        }
      }
  }
  cout << s;
  return 0;
}
