#include <bits/stdc++.h>
using namespace std;
int get(int n) {
  if (n == 0) return 1;
  int ret = 0;
  while (n) {
    n /= 7;
    ++ret;
  }
  return ret;
}
int solve(int mask, int n) {
  vector<int> vec;
  for (int i = 0; i < (7); ++i)
    if ((1 << i) & mask) vec.push_back(i);
  int ret = 0;
  do {
    int tmp = 0;
    for (int x : vec) {
      tmp = tmp * 7 + x;
    }
    if (tmp <= n) ++ret;
  } while (next_permutation(vec.begin(), vec.end()));
  return ret;
}
int main() {
  int n, m;
  while (cin >> n >> m) {
    --n, --m;
    int len1 = get(n), len2 = get(m);
    int ret = 0;
    int mask = (1 << 7) - 1;
    for (int mask1 = 0; mask1 < (1 << 7); ++mask1) {
      if (__builtin_popcount(mask1) == len1) {
        int a = solve(mask1, n);
        int tmp = mask ^ mask1;
        if (a)
          for (int mask2 = tmp; mask2; mask2 = (mask2 - 1) & tmp) {
            if (__builtin_popcount(mask2) == len2) {
              int b = solve(mask2, m);
              ret += a * b;
            }
          }
      }
    }
    cout << ret << endl;
  }
  return 0;
}
