#include <bits/stdc++.h>
using namespace std;
string base7(int x) {
  string str;
  while (x) {
    str += ((x % 7) + '0');
    x /= 7;
  }
  if (!str.size()) str = "0";
  reverse(str.begin(), str.end());
  return str;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  string x = base7(n - 1), y = base7(m - 1);
  int whole = x.size() + y.size();
  if (whole > 7) {
    cout << 0 << endl;
    return 0;
  }
  string cur;
  for (int i = 0; i < 7; i++) cur += (i + '0');
  set<string> res;
  do {
    bool ok = true;
    ok &= cur.substr(0, x.size()) <= x;
    ok &= cur.substr(x.size(), y.size()) <= y;
    if (ok) res.insert(cur.substr(0, x.size() + y.size()));
  } while (next_permutation(cur.begin(), cur.end()));
  cout << res.size() << endl;
  return 0;
}
