#include <bits/stdc++.h>
uint32_t readu32() {
  int c;
  while ((c = getchar_unlocked()) < '0')
    ;
  uint32_t n = c & 15U;
  while ((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U);
  return n;
}
uint64_t readu64() {
  int c;
  while ((c = getchar_unlocked()) < '0')
    ;
  uint64_t n = c & 15U;
  while ((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U);
  return n;
}
int32_t read32() {
  int c;
  while ((c = getchar_unlocked()) < '-')
    ;
  bool neg = c == '-';
  if (neg) c = getchar_unlocked();
  uint32_t n = c & 15U;
  while ((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U);
  return neg ? -(int32_t)n : n;
}
int64_t read64() {
  int c;
  while ((c = getchar_unlocked()) < '-')
    ;
  bool neg = c == '-';
  if (neg) c = getchar_unlocked();
  uint64_t n = c & 15;
  while ((c = getchar_unlocked()) >= '0') n = n * 10 + (c & 15U);
  return neg ? -(int64_t)n : n;
}
template <typename F, F f>
struct no_arg_call {
  operator decltype(f())() { return f(); }
};
no_arg_call<decltype(&readu32), readu32> IU;
no_arg_call<decltype(&read32), read32> II;
no_arg_call<decltype(&readu64), readu64> IUL;
no_arg_call<decltype(&read64), read64> IL;
using namespace std;
int nd(int x) {
  int c = 7, d = 1;
  while (c < x) {
    c *= 7;
    d++;
  }
  return d;
}
int mm(int x, int nd) {
  int a = 0;
  while (nd--) {
    int b = 1 << (x % 7);
    if (b & a) return -1;
    a |= b;
    x /= 7;
  }
  return a;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n = IU, m = IU;
  int ndn = nd(n), ndm = nd(m);
  if (ndn + ndm > 7) {
    cout << 0;
    return 0;
  }
  int a = 0;
  for (int i = 0; i < n; i++) {
    int ma = mm(i, ndn);
    for (int j = 0; j < m; j++) {
      int mb = mm(j, ndm);
      if (!(ma & mb)) ++a;
    }
  }
  cout << a;
  return 0;
}
