#include <bits/stdc++.h>
using namespace std;
long long n, m, nn = n - 1, mm = m - 1, ns, ms, vis[15], c = 0;
void solve(int x, int cur, int hrss, int minn) {
  if (cur <= ns)
    hrss *= 7, hrss += x;
  else
    minn *= 7, minn += x;
  if (cur == ms + ns) {
    if (hrss < n && minn < m) c++;
    return;
  }
  for (int i = 0; i < 7; i++) {
    if (vis[i] == 0) {
      vis[i] = 1;
      solve(i, cur + 1, hrss, minn);
      vis[i] = 0;
    }
  }
}
int main() {
  cin >> n >> m;
  nn = n - 1, mm = m - 1;
  if (nn)
    while (nn) nn /= 7, ns++;
  else
    ns = 1;
  if (mm)
    while (mm) mm /= 7, ms++;
  else
    ms = 1;
  if (ns + ms > 7) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < 7; i++) {
    vis[i] = 1;
    solve(i, 1, 0, 0);
    vis[i] = 0;
  }
  cout << c << endl;
}
