#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
using namespace std;
long long n, m, ans = 0, nr[15], x, y;
map<long long, long long> viz;
long long calc(long long x) {
  long long res = 0;
  while (x) {
    res++;
    x /= 7;
  }
  return max(res, 1ll);
}
long long check() {
  long long s1 = 0, s2 = 0;
  for (long long i = 1; i <= x; i++) {
    s1 = s1 * 7 + nr[i];
  }
  for (long long i = x + 1; i <= x + y; i++) {
    s2 = s2 * 7 + nr[i];
  }
  if (s1 <= n - 1 && s2 <= m - 1) {
    return 1;
  }
  return 0;
}
void bkt(long long pos) {
  for (long long i = 0; i < 7; i++) {
    if (viz[i] == 1) {
      continue;
    }
    nr[pos] = i;
    viz[i] = 1;
    if (pos == x + y) {
      if (check() == 1) {
        ans++;
      }
    } else {
      bkt(pos + 1);
    }
    viz[i] = 0;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  x = calc(n - 1);
  y = calc(m - 1);
  if (x + y > 7) {
    return cout << 0, 0;
  }
  bkt(1);
  cout << ans << '\n';
}
