#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[10];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> m;
  int tamN = 0;
  int lol = max(1, n - 1);
  while (lol) {
    ++tamN;
    lol /= 7;
  }
  int tamM = 0;
  lol = max(1, m - 1);
  while (lol) {
    ++tamM;
    lol /= 7;
  }
  int d = tamN + tamM;
  int cont = 0;
  if (d > 7) {
    cout << "0" << '\n';
    return 0;
  }
  for (int i = 0; i < 128; ++i) {
    int bits = 0;
    for (int j = 0; j < 7; ++j)
      if (i & (1 << j)) arr[bits++] = j;
    if (bits == d) {
      do {
        int pot = 1, hor = 0, min = 0;
        for (int k = tamN - 1; k >= 0; --k) {
          hor += arr[k] * pot;
          pot *= 7;
        }
        pot = 1;
        for (int h = d - 1; h >= tamN; --h) {
          min += arr[h] * pot;
          pot *= 7;
        }
        if (hor < n && min < m) ++cont;
      } while (next_permutation(arr, arr + bits));
    }
  }
  cout << cont << '\n';
  return 0;
}
