#include <bits/stdc++.h>
using namespace std;
int length_n = -1, length_m = -1;
vector<int> base_7(long long n, bool isN, bool isM) {
  long long rem;
  int z;
  vector<int> v;
  while (!(n < 7)) {
    rem = n % 7;
    v.push_back(rem);
    n = n / 7;
  }
  v.push_back(n);
  if (isN) {
    z = length_n - v.size();
  }
  if (isM) {
    z = length_m - v.size();
  }
  for (int i = 1; i <= z; i++) v.push_back(0);
  return v;
}
bool hasSame(vector<int> v) {
  int i;
  int data[7] = {0};
  for (i = 0; i < v.size(); i++) {
    if (data[v[i]] == 0)
      data[v[i]] = 1;
    else
      break;
  }
  if (i == v.size())
    return true;
  else
    return false;
}
int main() {
  long long n, m, i, j, k, l, count = 0;
  scanf("%lld", &n);
  scanf("%lld", &m);
  bool check = false;
  vector<int> v, b;
  v = base_7(n - 1, true, false);
  length_n = v.size();
  v = base_7(m - 1, false, true);
  length_m = v.size();
  if (length_m + length_n <= 7) {
    for (i = 0; i < n; i++) {
      v = base_7(i, true, false);
      for (k = 0; k < m; k++) {
        b = base_7(k, false, true);
        if (hasSame(v) && hasSame(b)) {
          for (l = 0; l < b.size(); l++) {
            for (j = 0; j < v.size(); j++) {
              if (b[l] == v[j]) {
                check = true;
                break;
              }
            }
            if (j != v.size()) break;
          }
          if (check == false) {
            count += 1;
          }
        }
        check = false;
      }
    }
  }
  printf("%lld\n", count);
}
