#include <bits/stdc++.h>
using namespace std;
int reqd(int x) {
  if (!x) return 1;
  int ret = 0;
  while (x) {
    ret += 1;
    x /= 7;
  }
  return ret;
}
int n, m;
int a, b;
int ok(vector<int> arr) {
  long long pehla = 0, dusra = 0;
  for (int i = 0; i < a; i++) pehla = pehla * 7 + arr[i];
  for (int i = a; i < (a + b); i++) dusra = dusra * 7 + arr[i];
  if (pehla >= 0 && pehla < n && dusra >= 0 && dusra < m)
    return 1;
  else
    return 0;
}
void debug(vector<int> A) {
  for (int i = 0; i < (int)A.size(); i++) cerr << A[i] << ",";
  cerr << "\n\n";
}
int ans = 0;
void solve(vector<int> x, int tot) {
  if ((int)x.size() == tot) {
    ans += ok(x);
    return;
  }
  for (int aa = 0; aa < 7; aa++) {
    int f = 0;
    for (auto i : x)
      if (i == aa) f = 1;
    if (!f) {
      vector<int> temp = x;
      temp.push_back(aa);
      solve(temp, tot);
    }
  }
}
int main() {
  cin >> n >> m;
  a = reqd(n - 1);
  b = reqd(m - 1);
  int tot = a + b;
  if (tot > 7)
    printf("0");
  else {
    vector<int> x;
    solve(x, tot);
    printf("%d\n", ans);
  }
  return 0;
}
