#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
const long long LLINF = numeric_limits<long long>::max();
const unsigned long long ULLINF = numeric_limits<unsigned long long>::max();
const double PI = acos(-1.0);
long long n, m;
vector<int> hour, minute;
long long dpH[3000], dpM[3000];
void print(vector<int>& a) {
  for (int i : a) cout << i;
  cout << endl;
}
bool comp(vector<int>& a, vector<int>& b) {
  for (int i = 0; i < a.size(); i++) {
    if (a[i] != b[i]) return a[i] < b[i];
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int t = n - 1;
  if (!t) hour.push_back(0);
  while (t) {
    hour.push_back(t % 7);
    t /= 7;
  }
  t = m - 1;
  if (!t) minute.push_back(0);
  while (t) {
    minute.push_back(t % 7);
    t /= 7;
  }
  reverse((hour).begin(), (hour).end());
  reverse((minute).begin(), (minute).end());
  int len = hour.size();
  for (int mask = 1; mask < (1 << 7); mask++) {
    vector<int> cur;
    int pc = __builtin_popcount(mask);
    if (pc != len) continue;
    for (int i = 0; i < 7; i++)
      if (mask & (1 << i)) cur.push_back(i);
    sort((cur).begin(), (cur).end());
    do {
      if (comp(cur, hour)) dpH[mask]++;
    } while (next_permutation((cur).begin(), (cur).end()));
  }
  len = minute.size();
  for (int mask = 1; mask < (1 << 7); mask++) {
    vector<int> cur;
    int pc = __builtin_popcount(mask);
    if (pc != len) continue;
    for (int i = 0; i < 7; i++)
      if (mask & (1 << i)) cur.push_back(i);
    sort((cur).begin(), (cur).end());
    do {
      if (comp(cur, minute)) dpM[mask]++;
    } while (next_permutation((cur).begin(), (cur).end()));
  }
  long long ans = 0;
  for (int mask1 = 1; mask1 < (1 << 7); mask1++) {
    for (int mask2 = 1; mask2 < (1 << 7); mask2++) {
      if ((mask1 | mask2) == (mask1 ^ mask2) && dpH[mask1] && dpM[mask2])
        ans += dpH[mask1] * dpM[mask2];
    }
  }
  cout << ans;
  return 0;
}
