#include <bits/stdc++.h>
using namespace std;
vector<int> q, w;
int n, m, csz;
long long res;
void rec(int pos, int mask, bool ok = 1) {
  if (pos >= ((int)(q.size()))) {
    res++;
    return;
  }
  if (pos == ((int)(q.size())) - csz) ok = 1;
  int val = q[pos];
  if (!ok) val = 6;
  for (int i = 0; i <= val; ++i) {
    int OK = 0;
    if (ok == 1 && i == q[pos]) OK = 1;
    if (!(mask & (1 << i))) {
      w.push_back(i);
      rec(pos + 1, mask | (1 << i), OK);
      w.pop_back();
    }
  }
}
int main() {
  cin >> n >> m;
  n--, m--;
  int x = n;
  if (!x) q.push_back(0);
  while (x > 0) {
    q.push_back(x % 7);
    x /= 7;
  }
  reverse(q.begin(), q.end());
  x = m;
  if (!x) w.push_back(0);
  while (x > 0) {
    w.push_back(x % 7);
    x /= 7;
  }
  reverse(w.begin(), w.end());
  int ptr = 0;
  while (ptr < ((int)(w.size()))) {
    q.push_back(w[ptr++]);
  }
  csz = ((int)(w.size()));
  w.clear();
  rec(0, 0);
  cout << res << endl;
  return 0;
}
