#include <bits/stdc++.h>
using namespace std;
vector<long long int> hour, minute;
vector<bool> visited;
long long int solve(long long int index1, long long int index2, bool limit) {
  if (index2 == -1) {
    return 1;
  }
  if (index1 == -1) return solve(index1 - 1, index2, true);
  long long int endDigit, currentDigit, res;
  if (index1 >= 0) {
    if (limit)
      endDigit = hour[index1];
    else
      endDigit = 6;
    res = 0;
    for (currentDigit = 0; currentDigit <= endDigit; currentDigit++) {
      if (visited[currentDigit]) continue;
      visited[currentDigit] = true;
      res += solve(index1 - 1, index2, limit && currentDigit == endDigit);
      visited[currentDigit] = false;
    }
  } else {
    if (limit)
      endDigit = minute[index2];
    else
      endDigit = 6;
    res = 0;
    for (currentDigit = 0; currentDigit <= endDigit; currentDigit++) {
      if (visited[currentDigit]) continue;
      visited[currentDigit] = true;
      res += solve(index1, index2 - 1, limit && currentDigit == endDigit);
      visited[currentDigit] = false;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long int p1, p2, n, m, result;
  cin >> n >> m;
  n--;
  m--;
  if (n == 0) hour.push_back(0);
  while (n > 0) {
    hour.push_back(n % 7);
    n /= 7;
  }
  if (m == 0) minute.push_back(0);
  while (m > 0) {
    minute.push_back(m % 7);
    m /= 7;
  }
  visited.resize(7, false);
  result = solve(hour.size() - 1, minute.size() - 1, true);
  cout << result;
  return 0;
}
