#include <bits/stdc++.h>
using namespace std;
int res, x[20], n, m, nn, mm, total;
bool mark[20];
int calc(int n) {
  int ans = 0;
  n--;
  while (1) {
    ans++;
    n /= 7;
    if (n == 0) break;
  }
  return ans;
}
void duyet(int u) {
  if (u >= total) {
    int tmp = 0;
    for (int i = 0; i < nn; i++) tmp = tmp * 7 + x[i];
    if (tmp >= n) return;
    tmp = 0;
    for (int i = nn; i < total; i++) tmp = tmp * 7 + x[i];
    if (tmp >= m) return;
    res++;
    return;
  }
  for (int i = 0; i < 7; i++)
    if (!mark[i]) {
      x[u] = i;
      mark[i] = true;
      duyet(u + 1);
      mark[i] = false;
    }
}
int main() {
  cin >> n >> m;
  nn = calc(n);
  mm = calc(m);
  total = nn + mm;
  res = 0;
  if (total <= 7) {
    duyet(0);
  }
  cout << res;
  return 0;
}
