#include <bits/stdc++.h>
using namespace std;
int n, m, nd, md;
long long ans = 0;
bool vis[10];
string aimlas, aimpro;
int cal(int x, int fg) {
  int cnt = 0;
  string now;
  while (x) {
    cnt++;
    char op = x % 7 + '0';
    x /= 7;
    now += op;
  }
  reverse(now.begin(), now.end());
  if (fg == 1)
    aimpro = now;
  else
    aimlas = now;
  return cnt;
}
void dfsm(int x, string s) {
  if (x == md + 1) {
    if (s <= aimlas) ans++;
    return;
  }
  for (int i = 0; i < 7; i++) {
    if (!vis[i]) {
      vis[i] = true;
      char op = i + '0';
      dfsm(x + 1, s + op);
      vis[i] = false;
    }
  }
}
void dfsn(int x, string s) {
  if (x == nd + 1) {
    if (s <= aimpro) {
      string a;
      dfsm(1, a);
    }
    return;
  }
  for (int i = 0; i < 7; i++) {
    if (!vis[i]) {
      vis[i] = true;
      char op = i + '0';
      dfsn(x + 1, s + op);
      vis[i] = false;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  nd = cal(n - 1, 1);
  md = cal(m - 1, 2);
  if (nd == 0) nd = 1, aimpro = '0';
  if (md == 0) md = 1, aimlas = '0';
  memset(vis, false, sizeof(vis));
  string s;
  dfsn(1, s);
  printf("%I64d\n", ans);
  return 0;
}
