#include <bits/stdc++.h>
using namespace std;
int n, m, nb, mb;
long long f1[20][1 << 7][2], f2[20][1 << 7][2];
int calc(int x) {
  int tmp = x / 7;
  int res = 1;
  while (tmp) {
    tmp /= 7;
    res++;
  }
  return res;
}
long long dfs(long long f[][1 << 7][2], int n[], int nb, int mask, int on) {
  if (nb == 0) {
    return mask == 0;
  }
  long long &ans = f[nb][mask][on];
  if (ans != -1) return ans;
  ans = 0;
  for (int i = 0; i < (on ? n[nb] + 1 : 7); ++i) {
    if (!(mask & (1 << i))) continue;
    ans += dfs(f, n, nb - 1, mask - (1 << i), on && n[nb] == i);
  }
  return ans;
}
void solve(long long f[][1 << 7][2], int n, int nb) {
  int nn[20], tmp = n;
  for (int i = 0; i < nb; ++i) {
    nn[i + 1] = tmp % 7;
    tmp /= 7;
  }
  for (int i = 0; i < (1 << 7); ++i) {
    dfs(f, nn, nb, i, 1);
  }
}
int main() {
  cin >> n >> m;
  n--;
  m--;
  nb = calc(n);
  mb = calc(m);
  memset(f1, -1, sizeof(f1));
  memset(f2, -1, sizeof(f2));
  solve(f1, n, nb);
  solve(f2, m, mb);
  long long ans = 0;
  for (int i = 0; i < (1 << 7); ++i) {
    if (f1[nb][i][1] == -1) f1[nb][i][1] = 0;
    if (f2[mb][i][1] == -1) f2[mb][i][1] = 0;
  }
  for (int i = 0; i < (1 << 7); ++i) {
    for (int j = 0; j < (1 << 7); ++j) {
      if ((i & j) == 0) {
        ans += f1[nb][i][1] * f2[mb][j][1];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
