#include <bits/stdc++.h>
using namespace std;
string getstr(int64_t num) {
  if (num == 0) return "0";
  string r = "";
  while (num) {
    r += '0' + (num % 7);
    num /= 7;
  }
  reverse(r.begin(), r.end());
  return r;
}
void incr(string& s) {
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == '6') {
      s[i] = '0';
    } else {
      s[i]++;
      return;
    }
  }
  s[0] = '7';
}
int check(string& a, string& b) {
  vector<int> v(7, 0);
  for (auto c : a) v[c - '0']++;
  for (auto c : b) v[c - '0']++;
  for (auto c : v)
    if (c > 1) return 0;
  return 1;
}
int main() {
  int64_t a, b;
  cin >> a >> b;
  string H = getstr(a - 1);
  string M = getstr(b - 1);
  if (H.size() + M.size() > 7) {
    cout << 0 << endl;
    return 0;
  }
  string h = H;
  for (int i = 0; i < h.size(); i++) h[i] = '0';
  int64_t sol = 0;
  while (h <= H) {
    string m = M;
    for (int i = 0; i < m.size(); i++) m[i] = '0';
    while (m <= M) {
      sol += check(h, m);
      incr(m);
    }
    incr(h);
  }
  cout << sol << endl;
}
