#include <bits/stdc++.h>
using namespace std;
int get(int n) {
  int cur = 7, cnt = 1;
  while (cur < n) {
    cnt++;
    cur *= 7;
  }
  return cnt;
}
int num(vector<int> v) {
  int cur = 1, ans = 0;
  for (int i : v) {
    ans += i * cur;
    cur *= 7;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int x, y;
  cin >> x >> y;
  int tot = get(x) + get(y);
  if (tot > 7) {
    cout << "0" << endl;
    return 0;
  }
  int ans = 0;
  for (int mask = 0; mask < (1 << 7); mask++) {
    if (__builtin_popcount(mask) != tot) continue;
    vector<int> v;
    for (int i = 0; i < 7; i++)
      if (mask & (1 << i)) v.push_back(i);
    do {
      vector<int> f, s;
      for (int i = 0; i < get(x); i++) f.push_back(v[i]);
      for (int i = get(x); i < v.size(); i++) s.push_back(v[i]);
      if (num(f) < x && num(s) < y) ans++;
    } while (next_permutation(v.begin(), v.end()));
  }
  cout << ans << endl;
}
