#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> mm;
int getl(int x) {
  if (x == 0) return 1;
  int l = 0;
  while (x > 0) {
    l++;
    x /= 7;
  }
  return l;
}
void solve() {
  int n;
  int m;
  cin >> n >> m;
  int ans = 0;
  int arr[7] = {0, 1, 2, 3, 4, 5, 6};
  int l1 = getl(n - 1);
  int l2 = getl(m - 1);
  for (int t = 2; t <= 7; t++) {
    int br[7];
    for (int i = 0; i < 7 - t; i++) {
      br[i] = 0;
    }
    for (int i = 7 - t; i < 7; i++) br[i] = 1;
    int sz = t + 1;
    do {
      int ar[t + 1];
      int ind = 0;
      for (int i = 0; i < 7; i++) {
        if (br[i] == 1) {
          ar[ind++] = arr[i];
        }
      }
      ar[ind++] = 7;
      do {
        int z = 0;
        int z1 = 0;
        int i = 0;
        int fg = 0, fg1 = 0;
        for (; ar[i] != 7; i++) {
          z = z * 7 + ar[i];
          fg++;
        }
        if (ar[i] == 7) i++;
        for (; i < sz; i++) {
          z1 = z1 * 7 + ar[i];
          fg1++;
        }
        if (z < n && z1 < m && fg == l1 && fg1 == l2 &&
            mm[make_pair(z, z1)] == 0) {
          mm[make_pair(z, z1)] = 1;
          ans++;
        }
      } while (next_permutation(ar, ar + t + 1));
    } while (next_permutation(br, br + 7));
  }
  cout << ans;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  int TC = 1;
  for (int ZZ = 1; ZZ <= TC; ZZ++) {
    clock_t start = clock();
    solve();
    clock_t end = clock();
    cerr << "Time: " << (double)(end - start) / CLOCKS_PER_SEC << " seconds"
         << '\n';
  }
  return 0;
}
