#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {-1, 1, 0, 0, 1, -1, -1, 1};
int n, m, ai = 0, bi = 0;
ll a = 1, b = 1;
int p[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  while (a < n) a *= 7, ai++;
  while (b < m) b *= 7, bi++;
  ai = max(ai, 1);
  bi = max(bi, 1);
  if (ai + bi > 7) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  do {
    int h = 0, minu = 0;
    int i = 0;
    if (!is_sorted(p + ai + bi, p + 7)) continue;
    for (; i < ai; ++i) h = h * 7 + p[i];
    for (; i < ai + bi; ++i) minu = minu * 7 + p[i];
    if (h < n && minu < m) {
      ans++;
    }
  } while (next_permutation(p, p + 7));
  cout << ans << endl;
}
