#include <bits/stdc++.h>
using namespace std;
int calc(int x) {
  if (x == 0) return 1;
  int ret = 0;
  while (x) {
    ++ret;
    x /= 7;
  }
  return ret;
}
int ans;
int l1, l2;
bool vis[10];
int n, m;
void dfs(int d, int s) {
  if (d == l1 + l2) {
    ++ans;
    return;
  }
  if (d == l1) s = 0;
  for (int i = 0; i < (7); ++i)
    if (!vis[i]) {
      if (d < l1) {
        if (s * 7 + i <= n) {
          vis[i] = 1;
          dfs(d + 1, s * 7 + i);
          vis[i] = 0;
        }
      } else if (s * 7 + i <= m) {
        vis[i] = 1;
        dfs(d + 1, s * 7 + i);
        vis[i] = 0;
      }
    }
}
int main() {
  scanf("%d%d", &n, &m);
  --n, --m;
  l1 = calc(n), l2 = calc(m);
  ans = 0;
  dfs(0, 0);
  printf("%d\n", ans);
  return 0;
}
