#include <bits/stdc++.h>
using namespace std;
const int nmax = 10;
int p[nmax];
int a, b, mask, cnt, i, j, nr, n, m, nl, ml;
set<pair<int, int> > is;
int main() {
  cin >> n;
  cin >> m;
  int cn = n - 1, cm = m - 1;
  if (cn == 0)
    nl = 1;
  else
    while (cn) cn /= 7, nl++;
  if (cm == 0)
    ml = 1;
  else
    while (cm) cm /= 7, ml++;
  for (mask = 0; mask < (1 << 7); ++mask) {
    cnt = 0;
    for (j = 0; j < 7; ++j)
      if (mask & (1 << j)) p[cnt++] = j;
    if (cnt == nl + ml)
      ;
    else
      continue;
    do {
      for (i = 1; i < cnt; ++i) {
        a = b = 0;
        for (j = 0; j < i; ++j) a = a * 7 + p[j];
        for (j = i; j < cnt; ++j) b = b * 7 + p[j];
        if (a < n && b < m) is.insert(make_pair(a, b));
      }
    } while (next_permutation(p, p + cnt));
  }
  cout << is.size() << '\n';
  return 0;
}
