#include <bits/stdc++.h>
using namespace std;
long cnt_n = 1, cnt_m = 1;
bool check(long u, long v) {
  set<long> a;
  for (long i = 0; i < cnt_n; i++) {
    a.insert(u % 7);
    u /= 7;
  }
  for (long j = 0; j < cnt_m; j++) {
    a.insert(v % 7);
    v /= 7;
  }
  if (a.size() == cnt_n + cnt_m) return true;
  return false;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long n, m;
  cin >> n >> m;
  long temp = n - 1;
  while (true) {
    temp /= 7;
    if (!temp) break;
    cnt_n++;
  }
  temp = m - 1;
  while (temp > 0) {
    temp /= 7;
    if (!temp) break;
    cnt_m++;
  }
  if (cnt_n + cnt_m > 7) {
    cout << 0;
    return 0;
  }
  long ans = 0;
  for (long i = 0; i <= n - 1; i++)
    for (long j = 0; j <= m - 1; j++)
      if (check(i, j)) ans++;
  cout << ans;
  return 0;
}
