#include <bits/stdc++.h>
using namespace std;
int transition;
int dp[10][2][1 << 9];
int solve(int idx, int tight, int mask, string &s) {
  if (idx == s.size()) {
    return __builtin_popcount(mask) == s.size();
  }
  if (dp[idx][tight][mask] != -1) return dp[idx][tight][mask];
  int &ans = dp[idx][tight][mask];
  ans = 0;
  if (idx == transition) {
    for (int i = 0; i <= s[idx] - '0'; i++) {
      ans += solve(idx + 1, s[idx] - '0' == i, mask | (1 << i), s);
    }
  } else {
    if (tight) {
      for (int i = 0; i <= s[idx] - '0'; i++) {
        ans += solve(idx + 1, s[idx] - '0' == i, mask | (1 << i), s);
      }
    } else {
      for (int i = 0; i < 7; i++) {
        ans += solve(idx + 1, 0, mask | (1 << i), s);
      }
    }
  }
  return ans;
}
string base7(int n) {
  string ans;
  if (n == 0) {
    ans.push_back('0');
    return ans;
  }
  while (n) {
    ans.push_back('0' + n % 7);
    n /= 7;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  m--;
  n--;
  memset(dp, -1, sizeof(dp));
  string hours = base7(n);
  string minutes = base7(m);
  string s = hours + minutes;
  transition = hours.size();
  if (s.size() > 7)
    cout << 0 << "\n";
  else {
    cout << solve(0, 1, 0, s) << "\n";
  }
  return 0;
}
