#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int B = 7;
vector<int> convert(int n) {
  vector<int> res;
  while (n) {
    res.push_back(n % B);
    n /= B;
  }
  if (res.empty()) {
    res.push_back(0);
  }
  reverse(begin(res), end(res));
  return res;
}
int dp[40][2][(1 << B) + 5];
vector<int> calc(int n) {
  vector<int> nn = convert(n);
  memset(dp, 0, sizeof dp);
  dp[0][1][0] = 1;
  for (int i = 0; i < (int)((int)(nn).size()); ++i)
    for (int eq = 0; eq < (int)2; ++eq)
      for (int mask = 0; mask < (int)1 << B; ++mask) {
        int cur_dp = dp[i][eq][mask];
        if (!cur_dp) {
          continue;
        }
        for (int nxt = 0; nxt < (int)B; ++nxt) {
          if (eq && nxt > nn[i]) {
            continue;
          }
          if (mask & (1 << nxt)) {
            continue;
          }
          int neq = eq && (nxt == nn[i]);
          int nmask = mask | (1 << nxt);
          dp[i + 1][neq][nmask] += cur_dp;
        }
      }
  vector<int> res(1 << B, 0);
  for (int mask = 0; mask < (int)1 << B; ++mask)
    for (int eq = 0; eq < (int)2; ++eq) {
      res[mask] += dp[((int)(nn).size())][eq][mask];
    }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> dp_n = calc(n - 1);
  vector<int> dp_m = calc(m - 1);
  long long ans = 0;
  for (int mask_n = 0; mask_n < (int)1 << B; ++mask_n)
    for (int mask_m = 0; mask_m < (int)1 << B; ++mask_m) {
      if ((mask_n & mask_m) == 0) {
        ans += dp_n[mask_n] * 1ll * dp_m[mask_m];
      }
    }
  cout << ans << endl;
  return 0;
}
