#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415;
int n, m, c[8], nn, mm, rs;
map<pair<int, int>, bool> u;
int main() {
  cin >> n >> m;
  for (int i = 0; i < 7; i++) c[i] = i;
  int copn = n, copm = m;
  copn--, copm--;
  if (!copn)
    nn = 1;
  else
    while (copn) copn /= 7, nn++;
  if (!copm)
    mm = 1;
  else
    while (copm) copm /= 7, mm++;
  if (nn + mm > 7) return cout << 0, 0;
  do {
    int nnn = 0, mmm = 0;
    for (int i = 0; i < min(8, mm + nn); i++) {
      if (i < nn)
        nnn = nnn * 7 + c[i];
      else
        mmm = mmm * 7 + c[i];
    }
    if (mmm < m && nnn < n && !u[{nnn, mmm}]) u[{nnn, mmm}] = 1;
  } while (next_permutation(c, c + 7));
  cout << u.size();
  return 0;
}
