#include <bits/stdc++.h>
using namespace std;
long long m7[15], n7[15], k = 0, l = 0, cnt[10], crt[10];
long long m, n;
long long ans = 0, temp;
int pandigital() {
  for (int i = 0; i < 7; i++) cnt[i] = 0;
  for (int i = 0; i < l + k; i++) cnt[crt[i]]++;
  for (int i = 0; i < 7; i++)
    if (cnt[i] > 1) return 0;
  return 1;
}
int n1() {
  for (int i = l - 1; i >= 0; i--) {
    if (crt[i] < n7[i])
      return 1;
    else {
      if (crt[i] > n7[i]) return 0;
    }
  }
  return 1;
}
int m1() {
  for (int i = l + k - 1; i >= l; i--) {
    if (crt[i] < m7[i - l])
      return 1;
    else {
      if (crt[i] > m7[i - l]) return 0;
    }
  }
  return 1;
}
void call() {
  for (int i = 0; i < 10; i++) crt[i] = 0;
  int p, q, r;
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j <= n; j++) {
      p = 0, r = j;
      for (int z = 0; z < l + k; z++) crt[z] = 0;
      while (r > 0) crt[p++] = r % 7, r = r / 7;
      p = l, r = i;
      while (r > 0) crt[p++] = r % 7, r = r / 7;
      if (pandigital()) {
        ans += m1() * n1();
      }
    }
  }
}
int main() {
  long long p, q;
  cin >> m >> n;
  m--, n--;
  p = m, q = n;
  if (m == 0) k = 1, m7[0] = 0;
  if (n == 0) l = 1, n7[0] = 0;
  while (n > 0) {
    n7[l++] = n % 7, n /= 7;
  }
  while (m > 0) {
    m7[k++] = m % 7, m /= 7;
  }
  m = p, n = q;
  if (k + l > 7) {
    cout << "0" << endl;
    return 0;
  }
  call();
  cout << ans << endl;
  return 0;
}
