#include <bits/stdc++.h>
using namespace std;
int howManyDigits(int n) {
  if (n == 0) return 1;
  int d = 0;
  while (n) {
    n /= 7;
    ++d;
  }
  return d;
}
int digitsToNum(int k, int* digits) {
  int d = 0;
  for (int i = 0; i < k; ++i) d = d * 7 + digits[i];
  return d;
}
void search(int k, int* picked, int dn, int dm, int& ans, int n, int m) {
  if (k == dn + dm) {
    if (digitsToNum(dn, picked) < n && digitsToNum(dm, picked + dn) < m) {
      ++ans;
    }
    return;
  }
  bool flag[7];
  for (int i = 0; i < 7; ++i) {
    flag[i] = false;
  }
  for (int i = 0; i < k; ++i) {
    flag[picked[i]] = true;
  }
  for (int i = 0; i < 7; ++i) {
    if (!flag[i]) {
      picked[k] = i;
      search(k + 1, picked, dn, dm, ans, n, m);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int howManyDigitsForN = howManyDigits(n - 1);
  int howManyDigitsForM = howManyDigits(m - 1);
  if (howManyDigitsForN + howManyDigitsForM > 7) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  int picked[7];
  search(0, picked, howManyDigitsForN, howManyDigitsForM, ans, n, m);
  cout << ans << endl;
  return 0;
}
