#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > s;
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  long long t = 0, pow = 7;
  int hr = 0, mn = 0;
  if (n == 1) hr = 1;
  if (m == 1) mn = 1;
  while (t < n - 1) {
    t = pow - 1;
    hr++;
    pow *= 7;
  }
  t = 0;
  pow = 7;
  while (t < m - 1) {
    t = pow - 1;
    mn++;
    pow *= 7;
  }
  if (hr + mn > 7) {
    printf("%d\n", 0);
    return 0;
  }
  int min, hour;
  vector<int> a;
  for (int i = 0; i < 7; i++) a.push_back(i);
  do {
    min = 0;
    hour = 0;
    for (int i = 6; i > 6 - mn; i--) {
      min = min * 7 + a[i];
    }
    for (int i = 6 - mn; i > 6 - mn - hr; i--) hour = hour * 7 + a[i];
    if (hour <= n - 1 && min <= m - 1) {
      s.insert(make_pair(hour, min));
    }
  } while (next_permutation(a.begin(), a.end()));
  printf("%d\n", s.size());
  return 0;
}
