#include <bits/stdc++.h>
using namespace std;
int nc[2], n, m, ans, vv[2];
bool vis[8];
void dfs(int ip, int id, long long vl) {
  int i, j, s, p, q;
  long long nv;
  if (id >= nc[ip]) {
    if (ip == 0)
      dfs(1, 0, 0);
    else
      ans++;
    return;
  }
  for (i = 0; i < 7; i++) {
    if (!vis[i]) {
      nv = vl * 7 + i;
      if (nv < vv[ip]) {
        vis[i] = true;
        dfs(ip, id + 1, nv);
        vis[i] = false;
      }
    }
  }
}
int main() {
  int i, j;
  scanf("%d%d", &n, &m);
  memset(vis, false, sizeof(vis));
  ans = 0;
  i = n - 1;
  memset(nc, 0, sizeof(nc));
  vv[0] = n;
  vv[1] = m;
  while (i) {
    nc[0]++;
    i /= 7;
  }
  i = m - 1;
  while (i) {
    nc[1]++;
    i /= 7;
  }
  nc[0] = max(1, nc[0]);
  nc[1] = max(1, nc[1]);
  dfs(0, 0, 0);
  printf("%d\n", ans);
}
