#include <bits/stdc++.h>
using namespace std;
int Count(int x) {
  int cnt = 0;
  while (x) {
    cnt++;
    x = x / 7;
  }
  return cnt;
}
int L, R;
int ans = 0;
int n, m;
bool visit[123];
void dfs2(int step, int now, int k) {
  if (step == R) {
    if (now <= m) ans++;
    return;
  }
  int i;
  int Std = now;
  for (i = 0; i <= 6; i++) {
    if (visit[i] == false) {
      visit[i] = true;
      now = Std + k * i;
      dfs2(step + 1, now, k * 7);
      visit[i] = false;
    }
  }
}
void dfs1(int step, int now, int k) {
  if (step == L) {
    if (now <= n) dfs2(0, 0, 1);
    return;
  }
  int i;
  int Std = now;
  for (i = 0; i <= 6; i++) {
    if (visit[i] == false) {
      visit[i] = true;
      now = Std + k * i;
      dfs1(step + 1, now, k * 7);
      visit[i] = false;
    }
  }
}
int main() {
  cin >> n >> m;
  L = Count(n - 1);
  R = Count(m - 1);
  n--;
  m--;
  if (L == 0) L = 1;
  if (R == 0) R = 1;
  if (L + R > 7) {
    printf("0\n");
    return 0;
  }
  dfs1(0, 0, 1);
  cout << ans << endl;
  return 0;
}
