#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long l1, l2;
int get7(int x) {
  int ans = 0;
  do {
    x /= 7;
    ans++;
  } while (x);
  return ans;
}
int arr[] = {0, 1, 2, 3, 4, 5, 6};
bool check() {
  long long a = 0;
  for (int i = 0; i < l1; i++) {
    a = a * 7 + arr[i];
  }
  long long b = 0;
  for (int i = l1; i < l1 + l2; i++) {
    b = b * 7 + arr[i];
  }
  if (a >= n) return false;
  if (b >= m) return false;
  return true;
}
int mark[10];
int ans;
void bt(int n, int x = 0) {
  if (n == 0) {
    if (check()) ans++;
    return;
  }
  for (int i = 0; i < 7; i++) {
    if (mark[i]) continue;
    mark[i] = 1;
    arr[x] = i;
    bt(n - 1, x + 1);
    mark[i] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  l1 = get7(n - 1);
  l2 = get7(m - 1);
  if (l1 + l2 > 7) {
    puts("0\n");
    return 0;
  }
  bt(l1 + l2);
  cout << ans << endl;
  return 0;
}
