#include <bits/stdc++.h>
using namespace std;
int quick_pow(int a, int b, int MOD) {
  a %= MOD;
  int res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    b /= 2;
    a = (a * a) % MOD;
  }
  return res;
}
const int maxn = 200000 + 10;
const int MOD = 1e9 + 7;
vector<int> bit1, bit2;
int cntn, cntm;
int cal1(int n) {
  int res = 0;
  while (n) {
    res++;
    n /= 7;
  }
  return res;
}
int caln(int n) {
  int res = 0;
  bit1.clear();
  while (n) {
    res++;
    bit1.push_back(n % 7);
    n /= 7;
  }
  while (bit1.size() < cntn) bit1.push_back(0);
  return res;
}
int calm(int n) {
  int res = 0;
  bit2.clear();
  while (n) {
    res++;
    bit2.push_back(n % 7);
    n /= 7;
  }
  while (bit2.size() < cntm) bit2.push_back(0);
  return res;
}
bool ok() {
  int v[20];
  memset(v, 0, sizeof(v));
  int i;
  for (i = 0; i < bit1.size(); i++) {
    if (v[bit1[i]]) return false;
    v[bit1[i]]++;
  }
  for (i = 0; i < bit2.size(); i++) {
    if (v[bit2[i]]) return false;
    v[bit2[i]]++;
  }
  return true;
}
int main() {
  int i, j, n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    if (n > 1)
      cntn = cal1(n - 1);
    else
      cntn = 1;
    if (m > 1)
      cntm = cal1(m - 1);
    else
      cntm = 1;
    if (cntn + cntm >= 8) {
      puts("0");
      continue;
    }
    int res = 0;
    for (i = 0; i < n; i++) {
      caln(i);
      for (j = 0; j < m; j++) {
        calm(j);
        if (ok()) {
          res++;
        }
      }
    }
    printf("%d\n", (res));
  }
  return 0;
}
