#include <bits/stdc++.h>
using namespace std;
int nr1, nr2, n, m, ver[10];
bool add(int el, int nrr) {
  int nu = 0;
  while (el) {
    int c = el % 7;
    el /= 7;
    ++nu;
    if (ver[c]) return 0;
    ver[c] = 1;
  }
  for (nu++; nu <= nrr; ++nu) {
    int c = 0;
    if (ver[c]) return 0;
    ver[c] = 1;
  }
  return 1;
}
int main() {
  cin >> n >> m;
  int t = n - 1;
  while (t) {
    t /= 7;
    ++nr1;
  }
  t = m - 1;
  while (t) {
    t /= 7;
    ++nr2;
  }
  if (!nr1) nr1 = 1;
  if (!nr2) nr2 = 1;
  if (nr1 + nr2 > 7) {
    cout << 0;
    return 0;
  }
  int r = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      memset(ver, 0, sizeof(ver));
      if (!add(i, nr1) || !add(j, nr2)) continue;
      ++r;
    }
  cout << r;
  return 0;
}
