#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<int> nums = {0, 1, 2, 3, 4, 5, 6};
  int leftPlaces = 0, rightPlaces = 0;
  for (long long i = 1; i <= n - 1; i *= 7LL, leftPlaces++)
    ;
  for (long long i = 1; i <= m - 1; i *= 7LL, rightPlaces++)
    ;
  if (leftPlaces + rightPlaces > 7) {
    cout << "0\n";
    return 0;
  }
  leftPlaces = max(1, leftPlaces);
  rightPlaces = max(1, rightPlaces);
  set<vector<int> > s;
  do {
    vector<int> num;
    for (int x = 0; x < leftPlaces + rightPlaces; x++) num.push_back(nums[x]);
    int left = 0;
    for (int x = 0; x < leftPlaces; x++) {
      left = left * 7 + nums[x];
    }
    int right = 0;
    for (int x = leftPlaces; x < leftPlaces + rightPlaces; x++)
      right = right * 7 + nums[x];
    if (right <= m - 1 && left <= n - 1) {
      s.insert(num);
    }
  } while (next_permutation(nums.begin(), nums.end()));
  cout << s.size() << '\n';
}
