#include <bits/stdc++.h>
using namespace std;
int N, M, cntN, cntM;
int solve(int n, int m) {
  set<int> s;
  for (int i = (1), _b = (cntN); i <= _b; i++) {
    s.insert(n % 7);
    n /= 7;
  }
  for (int i = (1), _b = (cntM); i <= _b; i++) {
    s.insert(m % 7);
    m /= 7;
  }
  return s.size() == cntN + cntM;
}
int main(void) {
  cin >> N >> M;
  --N;
  --M;
  int tmp = N;
  while (tmp) {
    tmp /= 7;
    ++cntN;
  }
  if (!cntN) ++cntN;
  tmp = M;
  while (tmp) {
    tmp /= 7;
    ++cntM;
  }
  if (!cntM) ++cntM;
  if (cntN + cntM > 7) return cout << 0 << endl, 0;
  long long ans = 0;
  for (int i = (0), _b = (N); i <= _b; i++)
    for (int j = (0), _b = (M); j <= _b; j++) ans += solve(i, j);
  cout << ans << endl;
  return 0;
}
