#include <bits/stdc++.h>
using namespace std;
int n, m, ans, lena, len, a[10];
bool taken[10];
string maxH, maxM;
string toBase(long long n, int base) {
  if (!n) return "0";
  string num, ret;
  for (int i = (0); i <= (int)(base - 1); ++i) num += (char)('0' + i);
  while (n) ret += num[n % base], n /= base;
  reverse(ret.begin(), ret.end());
  return ret;
}
long long convert(string st) {
  stringstream ss(st);
  long long ret;
  ss >> ret;
  return ret;
}
void solve(int i) {
  if (i == len) {
    string hours, mins;
    for (int j = (0); j <= (int)(lena - 1); ++j) hours += (char)(a[j] + '0');
    for (int j = (lena); j <= (int)(len - 1); ++j) mins += (char)(a[j] + '0');
    ans += convert(hours) < convert(maxH) && convert(mins) < convert(maxM);
    return;
  }
  for (int j = (0); j <= (int)(6); ++j) {
    if (!taken[j]) {
      a[i] = j;
      taken[j] = true;
      solve(i + 1);
      taken[j] = false;
    }
  }
}
int main() {
  cin >> n >> m;
  maxH = toBase(n - 1, 7), maxM = toBase(m - 1, 7);
  lena = ((int)(maxH).size()), len = lena + ((int)(maxM).size());
  maxH = toBase(n, 7), maxM = toBase(m, 7);
  if (len > 7) {
    cout << 0;
    return 0;
  }
  solve(0);
  cout << ans;
}
