#include <bits/stdc++.h>
using namespace std;
int cnt;
map<pair<int, int>, int> s;
void f(int a[], int n, int m, int hrs, int mns) {
  int hours = 0, minutes = 0;
  for (int i = 0; i < hrs; i++) hours = hours * 7 + a[i];
  for (int i = hrs; i < hrs + mns; i++) minutes = minutes * 7 + a[i];
  if (hours < n && minutes < m) {
    s[{hours, minutes}]++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    int n, m;
    cin >> n >> m;
    int t = n, k = m;
    int hh = 0, mm = 0;
    n--;
    m--;
    if (n == 0) hh = 1;
    if (m == 0) mm = 1;
    while (n) {
      hh++;
      n /= 7;
    }
    while (m) {
      mm++;
      m /= 7;
    }
    if (hh + mm > 7) return cout << 0, 0;
    int per[7] = {0, 1, 2, 3, 4, 5, 6};
    do {
      f(per, t, k, hh, mm);
    } while (next_permutation(per, per + 7));
    cout << (long long int)s.size();
  }
  return 0;
}
