#include <bits/stdc++.h>
using namespace std;
int n, m;
int fn[128], fm[128];
void take(int x, int sx, int a[]) {
  int k, z = 0;
  while (sx--) {
    k = x % 7, x /= 7;
    if (z & (1 << k)) return;
    z |= 1 << k;
  }
  a[z]++;
}
int NoD(int x) {
  if (!x) return 1;
  int sl = 0;
  while (x > 0) sl++, x /= 7;
  return sl;
}
int main() {
  cin >> n >> m;
  int sn = NoD(n - 1), sm = NoD(m - 1);
  if (sn + sm > 7) return cout << 0, 0;
  for (int i = 0; i < n; i++) take(i, sn, fn);
  for (int i = 0; i < m; i++) take(i, sm, fm);
  int ans = 0;
  for (int i = 0; i < 128; i++)
    for (int j = 0; j < 128; j++)
      if ((i & j) == 0) ans += fn[i] * fm[j];
  cout << ans;
  return 0;
}
