#include <bits/stdc++.h>
using namespace std;
int f[7];
int to_base(int x) {
  int ret = 0;
  if (x == 0) {
    f[x]++;
    return 1;
  }
  while (x) {
    ret++;
    f[x % 7]++;
    x /= 7;
  }
  return ret;
}
int main() {
  int n, m;
  cin >> n >> m;
  int nlen = to_base(n - 1);
  int mlen = to_base(m - 1);
  if (nlen + mlen > 7)
    puts("0");
  else {
    int ans = 0;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) {
        memset(f, 0, sizeof f);
        int ilen = to_base(i);
        while (ilen < nlen) f[0]++, ilen++;
        int jlen = to_base(j);
        while (jlen < mlen) f[0]++, jlen++;
        int bad = 0;
        for (int k = 0; k < 7; ++k)
          if (f[k] > 1) bad = 1;
        if (bad == 0) ans++;
      }
    cout << ans << endl;
  }
}
