#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long req1 = 0, req2 = 0;
  long long n_ = n - 1;
  while (n_) {
    req1++;
    n_ /= 7;
  }
  if (req1 == 0) {
    req1++;
  }
  long long m_ = m - 1;
  while (m_) {
    req2++;
    m_ /= 7;
  }
  if (req2 == 0) {
    req2 = 1;
  }
  if (req1 + req2 > 7) {
    cout << 0 << endl;
  } else {
    long long maxN = 1;
    for (long long i = 0; i < req1 + req2; i++) {
      maxN *= 7;
    }
    long long alternatives = 0;
    for (long long i = 0; i < maxN; i++) {
      long long current = i;
      long long used[7] = {0, 0, 0, 0, 0, 0, 0};
      bool ok = true;
      long long currentN = 0;
      for (long long i = 0; i < req1; i++) {
        long long digit = current % 7;
        currentN = currentN * 7 + digit;
        current /= 7;
        if (used[digit]) {
          ok = false;
        }
        used[digit] = 1;
        if (currentN >= n) {
          ok = false;
        }
      }
      long long currentM = 0;
      for (long long i = 0; i < req2; i++) {
        long long digit = current % 7;
        currentM = currentM * 7 + digit;
        current /= 7;
        if (used[digit]) {
          ok = false;
        }
        used[digit] = 1;
        if (currentM >= m) {
          ok = false;
        }
      }
      if (ok) {
        alternatives++;
      }
    }
    cout << alternatives << endl;
  }
}
