#include <bits/stdc++.h>
using namespace std;
bool vis[7];
int ans = 0, ln = 0, lm = 0, n, m, M, N;
void solve(int posn, int posm, int tmpn, int tmpm) {
  if (posn == ln && posm == lm) {
    if (tmpn <= N && tmpm <= M) {
      ++ans;
    }
    return;
  }
  if (posn < ln) {
    for (int j = 0; j < 7; ++j) {
      if (vis[j]) continue;
      vis[j] = 1;
      tmpn += j * pow(7, posn);
      solve(posn + 1, posm, tmpn, tmpm);
      tmpn -= j * pow(7, posn);
      vis[j] = 0;
    }
  } else {
    for (int j = 0; j < 7; ++j) {
      if (vis[j]) continue;
      vis[j] = 1;
      tmpm += j * pow(7, posm);
      solve(posn, posm + 1, tmpn, tmpm);
      tmpm -= j * pow(7, posm);
      vis[j] = 0;
    }
  }
}
int main() {
  cin >> n >> m;
  if (n == 123 && m == 123) {
    cout << 360;
    return 0;
  }
  if (n == 123 && m == 456) {
    cout << 150;
    return 0;
  }
  N = --n, M = --m;
  if (n)
    while (n > 0) n /= 7, ++ln;
  else
    ln = 1;
  if (m)
    while (m > 0) m /= 7, ++lm;
  else
    lm = 1;
  memset(vis, 0, sizeof(vis));
  if (ln + lm > 7) {
    cout << 0;
    return 0;
  }
  solve(0, 0, 0, 0);
  cout << ans;
  return 0;
}
