#include <bits/stdc++.h>
using namespace std;
int b[7] = {0, 1, 2, 3, 4, 5, 6};
map<pair<int, int>, int> mapp;
int n, m;
int getbit(int x) {
  int ans = 0;
  if (x == 0) return 1;
  while (x) {
    ans++;
    x /= 7;
  }
  return ans;
}
bool judge(int pos, int len) {
  int base = 1;
  int h = 0;
  for (int i = pos - 1; i >= 0; i--) {
    h += b[i] * base;
    base *= 7;
  }
  int mt = 0;
  base = 1;
  for (int i = len - 1; i >= pos; i--) {
    mt += b[i] * base;
    base *= 7;
  }
  if (h <= n && mt <= m) {
    if (mapp[make_pair(h, mt)])
      return 0;
    else {
      mapp[make_pair(h, mt)] = 1;
      return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%d %d", &n, &m);
  int ans = 0;
  --n, --m;
  int p1 = getbit(n);
  int p2 = getbit(m);
  int p = p1 + p2;
  if (p > 7)
    ans = 0;
  else {
    do {
      for (int i = 1; i < p; i++) {
        if (judge(i, p)) ans++;
      }
    } while (next_permutation(b, b + 7));
  }
  printf("%d\n", ans);
  return 0;
}
