#include <bits/stdc++.h>
int N, M;
int lenN, lenM;
int f(int x) {
  int len = 1;
  for (auto max = 7LL; max < x; max *= 7, ++len)
    ;
  return len;
}
bool ok(const std::vector<int>& xs) {
  int count[7]{0};
  for (int x : xs)
    if (count[x]++) return false;
  int n = 0, m = 0;
  for (int i = lenN - 1; i >= 0; n *= 7, n += xs[i--])
    ;
  for (int i = lenM - 1; i >= 0; m *= 7, m += xs[lenN + i--])
    ;
  return n < N && m < M;
}
int main() {
  std::cin >> N >> M;
  lenN = f(N), lenM = f(M);
  int L = lenN + lenM;
  if (L > 7) return std::cout << 0, 0;
  std::vector<int> xs(L);
  int count = 0;
  for (;; count += ok(xs)) {
    int i = L - 1;
    for (; i >= 0; --i)
      if (++xs[i] > 6)
        xs[i] = 0;
      else
        break;
    if (i < 0) break;
  }
  std::cout << count;
}
