#include <bits/stdc++.h>
using namespace std;
long long int n, m, cn, cm;
long long int n7[20] = {0}, m7[20] = {0};
long long int dp1[25][(1 << 7) + 10], dp2[25][(1 << 7) + 10];
long long int compute(long long int i, long long int j, long long int v,
                      long long int z) {
  if (i == -1) {
    if (j == -1) {
      return 1;
    }
    if (z == 0 && dp2[j][v] != -1) return dp2[j][v];
    long long int ans = 0, k, end = 6;
    if (z) end = m7[j];
    for (k = 0; k <= end; k++) {
      if ((v & (1 << k)) == 0)
        ans = ans + compute(i, j - 1, (v | (1 << k)), (z & (k == end)));
    }
    if (z == 0) dp2[j][v] = ans;
    return ans;
  }
  if (z == 0 && dp1[i][v] != -1) return dp1[i][v];
  long long int ans = 0, k, end = 6;
  if (z) end = n7[i];
  for (k = 0; k <= end; k++) {
    if ((v & (1 << k)) == 0)
      ans = ans +
            compute(i - 1, j, (v | (1 << k)), ((z & (k == end)) || (i == 0)));
  }
  if (z == 0) dp1[i][v] = ans;
  return ans;
}
int main() {
  long long int i, j, ans;
  cin >> n >> m;
  cn = 0;
  cm = 0;
  n--;
  m--;
  while (n > 0) {
    n7[cn++] = n % 7;
    n /= 7;
  }
  while (m > 0) {
    m7[cm++] = m % 7;
    m /= 7;
  }
  if (cn == 0) cn = 1;
  if (cm == 0) cm = 1;
  memset(dp1, -1, sizeof(dp1));
  memset(dp2, -1, sizeof(dp2));
  ans = compute(cn - 1, cm - 1, 0, 1);
  cout << ans << "\n";
  return 0;
}
