#include <bits/stdc++.h>
using namespace std;
inline long long Rd() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void Rt(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10)
    Rt(x / 10), putchar(x % 10 + '0');
  else
    putchar(x + '0');
}
int Dig(int x) {
  if (!x) return 1;
  int Ret = 0;
  while (x) Ret++, x /= 7;
  return Ret;
}
int Ans, Use[10], b[10], Fd, Sd, n, m;
int Num(int l, int r) {
  int Ret = 0, Base = 1;
  for (int i = r; i >= (int)l; i--) {
    Ret += Base * b[i];
    Base *= 7;
  }
  return Ret;
}
void Dfs(int Nw, int Goal) {
  if (Nw == Goal + 1) {
    if (Num(1, Fd) < n && Num(Fd + 1, Fd + Sd) < m) Ans++;
    return;
  }
  for (int i = 0; i <= (int)6; i++)
    if (!Use[i]) {
      b[Nw] = i;
      Use[i] = 1;
      Dfs(Nw + 1, Goal);
      Use[i] = 0;
    }
}
int main() {
  n = Rd(), m = Rd();
  Fd = Dig(n - 1), Sd = Dig(m - 1);
  if (Fd + Sd >= 8) return puts("0"), 0;
  Dfs(1, Fd + Sd);
  Rt(Ans);
}
