#include <bits/stdc++.h>
using namespace std;
string convert(int x) {
  string res;
  if (x == 0) return "0";
  while (x) {
    res += ((x % 7) + '0');
    x /= 7;
  }
  reverse(res.begin(), res.end());
  return res;
}
int res = 0;
void search(string strn, string strm, int lenn, int lenm, string tmp, int len) {
  if (len == lenn + lenm) {
    string tmpn = tmp.substr(0, lenn);
    string tmpm = tmp.substr(lenn);
    if (atoi(tmpn.c_str()) <= atoi(strn.c_str()) &&
        atoi(tmpm.c_str()) <= atoi(strm.c_str())) {
      sort(tmp.begin(), tmp.end());
      bool find = true;
      for (int i = 1; i < len; i++) {
        if (tmp[i] == tmp[i - 1]) {
          find = false;
          break;
        }
      }
      if (find) res++;
    }
    return;
  }
  for (int i = 0; i <= 6; i++) {
    search(strn, strm, lenn, lenm, tmp + char('0' + i), len + 1);
  }
}
int main() {
  int n, m;
  string strn, strm;
  cin >> n >> m;
  strn = convert(n - 1);
  strm = convert(m - 1);
  int lenn = strn.length();
  int lenm = strm.length();
  if (lenn + lenm > 7) {
    cout << "0" << endl;
  } else {
    search(strn, strm, lenn, lenm, "", 0);
    cout << res << endl;
  }
  return 0;
}
