#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v1, v2;
int n, m;
int cal(int n) {
  int cnt = 0;
  if (n == 0) return 1;
  while (n) {
    n /= 7;
    cnt++;
  }
  return cnt;
}
bool calVal(vector<int> &v, int n) {
  int val = 0;
  for (int i = 0; i < v.size(); i++) {
    val *= 7;
    val += v[i];
  }
  if (val <= n) return 1;
  return 0;
}
void permute(vector<int> v, int &n, vector<vector<int> > &V) {
  if (calVal(v, n)) V.push_back(v);
  while (next_permutation(v.begin(), v.end())) {
    if (calVal(v, n))
      V.push_back(v);
    else
      break;
  }
}
void solve(int k, vector<int> &v, int &l, int n, vector<vector<int> > &V) {
  if (v.size() == l) {
    permute(v, n, V);
    return;
  }
  for (int i = k; i < 7; i++) {
    v.push_back(i);
    solve(i + 1, v, l, n, V);
    v.pop_back();
  }
}
bool distinct(vector<int> &v1, vector<int> &v2) {
  int a[7] = {};
  for (int i = 0; i < v1.size(); i++) a[v1[i]]++;
  for (int i = 0; i < v2.size(); i++) a[v2[i]]++;
  for (int i = 0; i < 7; i++) {
    if (a[i] > 1) return 0;
  }
  return 1;
}
int main() {
  int l1, l2, cnt = 0;
  vector<int> v;
  cin >> n >> m;
  l1 = cal(n - 1);
  l2 = cal(m - 1);
  if (l1 + l2 > 7) {
    cout << 0 << endl;
    return 0;
  }
  solve(0, v, l1, n - 1, v1);
  solve(0, v, l2, m - 1, v2);
  for (int i = 0; i < v1.size(); i++) {
    for (int j = 0; j < v2.size(); j++) {
      if (distinct(v1[i], v2[j])) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
