#include <bits/stdc++.h>
using namespace std;
vector<long long> v1, v2;
long long size1, size2, counter1[1000001];
long long counter2[1000001], visited1[10][2][100001], visited2[10][2][100001];
void recur2(long long pos, long long tt, long long msk) {
  if (pos == v2.size()) {
    counter2[msk]++;
    return;
  }
  long long limit, i;
  if (tt)
    limit = v2[pos];
  else
    limit = 6;
  for (i = 0; i <= limit; i++) {
    if (msk & (1 << i)) continue;
    if (!tt)
      recur2(pos + 1, 0, msk | (1 << i));
    else {
      if (i == v2[pos])
        recur2(pos + 1, 1, msk | (1 << i));
      else
        recur2(pos + 1, 0, msk | (1 << i));
    }
  }
}
void recur1(long long pos, long long tt, long long msk) {
  if (pos == v1.size()) {
    counter1[msk]++;
    return;
  }
  long long limit, i;
  if (tt)
    limit = v1[pos];
  else
    limit = 6;
  for (i = 0; i <= limit; i++) {
    if (msk & (1 << i)) continue;
    if (!tt)
      recur1(pos + 1, 0, msk | (1 << i));
    else {
      if (i == v1[pos])
        recur1(pos + 1, 1, msk | (1 << i));
      else
        recur1(pos + 1, 0, msk | (1 << i));
    }
  }
}
int main() {
  long long n, m, nn, mm, d, ans = 0;
  cin >> n >> m;
  nn = n;
  mm = m;
  nn--;
  mm--;
  while (nn > 0) {
    d = nn % 7;
    nn /= 7;
    v1.push_back(d);
  }
  reverse(v1.begin(), v1.end());
  size1 = v1.size();
  while (mm > 0) {
    d = mm % 7;
    mm /= 7;
    v2.push_back(d);
  }
  reverse(v2.begin(), v2.end());
  size2 = v2.size();
  if (size1 == 0)
    counter1[1]++;
  else
    recur1(0, 1, 0);
  if (size2 == 0)
    counter2[1]++;
  else
    recur2(0, 1, 0);
  for (int msk1 = 0; msk1 < (1 << 7); msk1++) {
    for (int msk2 = 0; msk2 < (1 << 7); msk2++) {
      int f = 0;
      for (int i = 0; i <= 6; i++) {
        if ((msk1 & (1 << i)) && (msk2 & (1 << i))) {
          f = 1;
          break;
        }
      }
      if (!f) ans += counter1[msk1] * counter2[msk2];
    }
  }
  cout << ans;
  return 0;
}
