#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-6, PI = acos(-1);
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int N = 1e5 + 5;
int n[2], d[2], t, ans;
int main() {
  scanf("%d%d", &n[0], &n[1]);
  for (int i = 0; i < 2; ++i) {
    t = n[i] - 1;
    while (t) d[i]++, t /= 7;
  }
  d[0] = max(1, d[0]);
  d[1] = max(1, d[1]);
  if (d[0] + d[1] > 7) return 0 * printf("0\n");
  vector<int> v;
  for (int i = 0; i < 7; ++i) v.push_back(i);
  set<vector<int> > s;
  do {
    int a = 0;
    for (int i = 0; i < d[0]; ++i) a = a * 7 + v[i];
    if (a >= n[0]) continue;
    a = 0;
    for (int i = 0; i < d[1]; ++i) a = a * 7 + v[i + d[0]];
    if (a >= n[1]) continue;
    vector<int> x;
    for (int i = 0; i < d[0] + d[1]; ++i) x.push_back(v[i]);
    if (s.count(x)) continue;
    s.insert(x);
    ans++;
  } while (next_permutation(v.begin(), v.end()));
  printf("%d\n", ans);
  return 0;
}
