#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long fact(long long n) {
  if (n <= 1) return 1;
  return n * fact(n - 1);
}
int main(int argc, char const *argv[]) {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m, ctr1 = 0, ctr2 = 0, temp;
  cin >> n >> m;
  temp = n - 1;
  do {
    temp /= 7;
    ++ctr1;
  } while (temp);
  temp = m - 1;
  do {
    temp /= 7;
    ++ctr2;
  } while (temp);
  if (ctr1 + ctr2 > 7)
    cout << "0\n";
  else {
    long long ctr = 0;
    vector<long long> dig(7, 0);
    bool valid = true;
    for (long long i = 0; i <= n - 1; ++i) {
      for (long long j = 0; j <= m - 1; ++j) {
        valid = true;
        for (long long k = 0; k <= 6; ++k) {
          dig[k] = 0;
        }
        temp = i;
        for (long long k = 1; k <= ctr1; ++k) {
          ++dig[temp % 7];
          temp /= 7;
        }
        temp = j;
        for (long long k = 1; k <= ctr2; ++k) {
          ++dig[temp % 7];
          temp /= 7;
        }
        for (long long k = 0; k <= 6; ++k)
          if (dig[k] > 1) {
            valid = false;
            break;
          }
        if (valid) ++ctr;
      }
    }
    cout << ctr << "\n";
  }
  return 0;
}
