#include <bits/stdc++.h>
using namespace std;
inline vector<string> __split(const string& s, char c) {
  vector<string> v;
  stringstream ss(s);
  string x;
  while (getline(ss, x, c)) v.emplace_back(x);
  return move(v);
}
inline void err(vector<string>::iterator it) {}
template <typename T, typename... Args>
inline void err(vector<string>::iterator it, T a, Args... args) {
  auto item = it->substr((*it)[0] == ' ', it->length());
  err(++it, args...);
}
static char buff[(int)1e6 + 17];
static constexpr long long inf = (long long)1e9 + 7ll;
inline void config_io(const bool& __fastio) {
  if (__fastio) {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
  }
  if (!std::string("").empty()) {
    assert(
        freopen(""
                ".in",
                "r", stdin));
    assert(
        freopen(""
                ".out",
                "w", stdout));
  }
}
const int maxn = (int)2e5 + 17;
long long n, m, lenn, lenm, ans;
int len(long long x) {
  int res = 0;
  if (x == 0) res = 1;
  for (; x > 0; x /= 7) ++res;
  return res;
}
void rcs(string& s) {
  if (((int)s.size()) == lenn + lenm) {
    long long pw = 1ll;
    long long a = 0ll, b = 0ll;
    for (int i = ((int)s.size()) - 1; i >= 0; --i, pw *= 7ll) {
      if (((int)s.size()) - i == lenm + 1) pw = 1ll;
      if (((int)s.size()) - i <= lenm) {
        b += pw * (s[i] - '0');
      } else {
        a += pw * (s[i] - '0');
      }
    }
    if (a < n && b < m) ++ans;
    return;
  }
  for (char c = '0'; c < '7'; ++c) {
    bool bad = false;
    for (auto cc : s)
      if (cc == c) bad = true;
    if (bad) continue;
    string t = s + c;
    rcs(t);
  }
}
int main() {
  config_io(false);
  scanf(
      "%lld"
      "%lld",
      &n, &m);
  lenn = len(n - 1), lenm = len(m - 1);
  if (lenn + lenm > 7) return printf("0\n"), 0;
  string s = "";
  rcs(s);
  printf(
      "%lld"
      "\n",
      ans);
  return 0;
}
