#include <bits/stdc++.h>
using namespace std;
const int N_ = 105;
int N, M, X, Y;
int len(int x) {
  for (int l = 1, v = 7;; l++) {
    if (v >= x) return l;
    v *= 7;
  }
}
set<long long> S;
bool chk[100];
void dfs(int i, long long p, long long q) {
  if (p >= N || q >= M) return;
  if (i == X + Y) {
    S.insert(p * (long long)1e9 + q);
    return;
  }
  for (int d = 0; d < 7; d++) {
    if (!chk[d]) {
      chk[d] = true;
      ((i < X ? p : q) *= 7) += d;
      dfs(i + 1, p, q);
      ((i < X ? p : q) -= d) /= 7;
      chk[d] = false;
    }
  }
}
int main() {
  scanf("%d %d", &N, &M);
  X = len(N), Y = len(M);
  if (X + Y > 7) return 0 & puts("0");
  dfs(0, 0, 0);
  printf("%lu\n", S.size());
  return 0;
}
