#include <bits/stdc++.h>
using namespace std;
int n, m, ln, lm;
int a[10];
int b[10];
int res;
void relax() {
  int x = 0;
  for (int i = 0; i < (int)(ln); ++i) x = x * 7 + a[i];
  int y = 0;
  for (int i = 0; i < (int)(lm); ++i) y = y * 7 + a[ln + i];
  if (x < n && y < m) {
    res++;
  }
}
void go(int p) {
  if (p == ln + lm) {
    relax();
    return;
  }
  for (int i = 0; i < (int)(7); ++i)
    if (!b[i]) {
      b[i] = 1;
      a[p] = i;
      go(p + 1);
      b[i] = 0;
    }
}
int main() {
  cin >> n >> m;
  int x;
  x = 1;
  while (x < n) x *= 7, ++ln;
  ln = max(ln, 1);
  x = 1;
  while (x < m) x *= 7, ++lm;
  lm = max(lm, 1);
  if (ln + lm > 7) {
    cout << 0 << endl;
    return 0;
  }
  go(0);
  cout << res << endl;
  return 0;
}
