#include <bits/stdc++.h>
using namespace std;
long long int digit_count(long long int a) {
  long long int count = 1;
  for (long long int i = 7; i < a; i *= 7) count++;
  return count;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int digit_n, digit_m;
  digit_n = digit_count(n);
  digit_m = digit_count(m);
  if (digit_n == 0) digit_n = 1;
  if (digit_m == 0) digit_m = 1;
  long long int ans = 0;
  if (digit_m + digit_n > 7)
    cout << 0 << endl;
  else {
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        long long int used[7] = {0};
        long long int base7_i, base7_j;
        long long int tempest = 0;
        for (long long int temp = i; tempest != digit_n; tempest++, temp /= 7) {
          used[temp % 7] += 1;
        }
        tempest = 0;
        for (long long int temp = j; tempest != digit_m; tempest++, temp /= 7) {
          used[temp % 7] += 1;
        }
        if (*max_element(used, used + 7) <= 1) ans++;
      }
    }
    cout << ans;
  }
  return 0;
}
