#include <bits/stdc++.h>
using namespace std;
long long pow(long long x, long long y) {
  if (y == 0) return 1;
  long long temp = 1;
  for (int i = 0; i < y; i++) temp *= x;
  return temp;
}
int main() {
  long long n, m, temp, cnt1 = 0, cnt2 = 0, res = 0;
  cin >> n >> m;
  n--, m--;
  if (n == 0)
    cnt1 = 1;
  else {
    temp = n;
    while (temp) cnt1++, temp /= 7;
  }
  if (m == 0)
    cnt2 = 1;
  else {
    temp = m;
    while (temp) cnt2++, temp /= 7;
  }
  if (cnt1 + cnt2 > 7) {
    cout << 0 << endl;
    return 0;
  }
  string str = "0123456";
  set<string> taken;
  do {
    string ho = str.substr(0, cnt1);
    string mi = str.substr(cnt1, cnt2);
    if (taken.count(ho + mi)) continue;
    taken.insert(ho + mi);
    long long hh = 0;
    for (int i = 0; i < cnt1; i++) hh += (ho[i] - '0') * pow(7, i);
    if (hh > n) continue;
    hh = 0;
    for (int i = 0; i < cnt2; i++) hh += (mi[i] - '0') * pow(7, i);
    if (hh > m) continue;
    res++;
  } while (next_permutation(str.begin(), str.end()));
  cout << res << endl;
  return 0;
}
