#include <bits/stdc++.h>
using namespace std;
long long int power[8];
int main() {
  long long int i, n, j, m;
  cin >> n >> m;
  power[0] = 1;
  for (i = 1; i < 8; i++) power[i] = 7 * power[i - 1];
  n--;
  m--;
  for (i = 0; i < 8; i++)
    if (power[i] > n) break;
  long long int digi_n = i;
  if (digi_n == 0) digi_n++;
  for (i = 0; i < 8; i++)
    if (power[i] > m) break;
  long long int digi_m = i;
  if (digi_m == 0) digi_m++;
  if (digi_m + digi_n > 7) {
    cout << "0\n";
    return 0;
  }
  long long int ans = 0;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= m; j++) {
      long long int counter = 0, z = i, y = j;
      bool flag = false;
      set<long long int> keep;
      keep.clear();
      while (counter < digi_n) {
        if (keep.find(i % 7) != keep.end()) flag = 1;
        keep.insert(i % 7), i /= 7, counter++;
      }
      counter = 0;
      while (counter < digi_m) {
        if (keep.find(j % 7) != keep.end()) flag = 1;
        keep.insert(j % 7), j /= 7, counter++;
      }
      if (!flag) ans++;
      i = z;
      j = y;
    }
  }
  cout << ans << endl;
  return 0;
}
