#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans;
bool vis[10];
int a[10], b[10];
int lenn, lenm;
int getLen(int x) {
  int tx = x;
  int len = 0;
  if (x == 0) return 1;
  while (tx > 0) {
    tx /= 7;
    len++;
  }
  return len;
}
void dfs2(int x) {
  if (x >= lenm + 1) {
    int tmp = 0, k = 1;
    for (int i = 1; i <= lenm; i++) {
      tmp += k * b[i];
      k *= 7;
    }
    if (tmp < m) {
      ans++;
    }
    return;
  }
  for (int i = 0; i < 7; i++)
    if (!vis[i]) {
      vis[i] = true;
      b[x] = i;
      dfs2(x + 1);
      vis[i] = false;
    }
}
void dfs1(int x) {
  if (x >= lenn + 1) {
    int tmp = 0, k = 1;
    for (int i = 1; i <= lenn; i++) {
      tmp += k * a[i];
      k *= 7;
    }
    if (tmp < n) dfs2(1);
    return;
  }
  for (int i = 0; i < 7; i++)
    if (!vis[i]) {
      vis[i] = true;
      a[x] = i;
      dfs1(x + 1);
      vis[i] = false;
    }
}
int main() {
  scanf("%d%d", &n, &m);
  lenn = getLen(n - 1);
  lenm = getLen(m - 1);
  if (lenn + lenm > 7) {
    puts("0");
    return 0;
  }
  memset(vis, false, sizeof(vis));
  ans = 0;
  dfs1(1);
  printf("%d\n", ans);
  return 0;
}
