#include <bits/stdc++.h>
using namespace std;
int ans = 0;
void check(int i, int dn, int dm, int n, int m) {
  int temp1 = 0;
  int i_temp = i;
  bool num_flag[10] = {0};
  vector<int> vv;
  while (i > 0) {
    vv.push_back(i % 7);
    i /= 7;
  }
  int sz = vv.size();
  while (sz < (dn + dm)) {
    vv.push_back(0);
    sz++;
  }
  bool err_flag = 0;
  for (int j = 0; j < dm; j++) {
    if (num_flag[vv[j]] == 1) {
      err_flag = 1;
      break;
    } else {
      num_flag[vv[j]] = 1;
    }
    temp1 = vv[j] + temp1 * 7;
  }
  if (temp1 > m) {
    err_flag = 1;
  }
  temp1 = 0;
  for (int j = dm; j < (dm + dn); j++) {
    if (num_flag[vv[j]] == 1) {
      err_flag = 1;
      break;
    } else {
      num_flag[vv[j]] = 1;
    }
    temp1 = vv[j] + temp1 * 7;
  }
  if (temp1 > n) {
    err_flag = 1;
  }
  if (err_flag == 0) {
    ans++;
  }
}
int num_digits(int n) {
  if (n == 0) return 1;
  int ans = 0;
  while (n > 0) {
    n /= 7;
    ans++;
  }
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  n--;
  m--;
  int dn = num_digits(n);
  int dm = num_digits(m);
  int digits = dm + dn;
  if (dm + dn > 7) {
    ans = 0;
  } else {
    int temp_tt = (int)(pow(7, digits) - 1);
    for (int i = 0; i <= temp_tt; i++) {
      check(i, dn, dm, n, m);
    }
  }
  cout << ans << endl;
}
