#include <bits/stdc++.h>
using namespace std;
long long int n, m;
string a, b;
string get(int n) {
  if (n == 0) return "0";
  string r;
  while (n) {
    r += n % 7 + '0';
    n /= 7;
  }
  return r;
}
long long int go(int i, long long int min, long long int sec) {
  if (min >= n) return 0;
  if (sec >= m) return 0;
  if (i == a.length() + b.length()) {
    if (min < n && sec < m) {
      string s = get(min), t = get(sec);
      int c[10] = {0};
      s += t;
      int f = 1;
      while (1) {
        if (s.length() == a.length() + b.length()) break;
        s += '0';
      }
      for (int k = 0; k <= s.length() - 1; k++) c[s[k] - '0']++;
      for (int k = 0; k <= 9; k++) {
        if (c[k] > 1) f = 0;
      }
      return f;
    }
    return 0;
  }
  long long int r = 0;
  if (i >= a.length())
    for (int j = 0; j <= 6; j++) r += go(i + 1, min, sec * 7 + j);
  else {
    for (int j = 0; j <= 6; j++) r += go(i + 1, min * 7 + j, sec);
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  a = get(n - 1), b = get(m - 1);
  if (a.length() + b.length() >= 9) {
    cout << "0";
    return 0;
  }
  long long int ans = go(0, 0, 0);
  cout << ans;
  return 0;
}
