#include <bits/stdc++.h>
using namespace std;
const long long int infinity = 9e18;
long long int base7(long long int n) {
  long long int dig = 0;
  while (n) {
    n = n / 7;
    dig++;
  }
  return dig;
}
long long int getNo(long long int n, long long int m) {
  long long int val = 0;
  long long int mul = 1;
  long long int dig = 0;
  set<int> s;
  while (n) {
    s.insert(n % 7);
    val = val + mul * (n % 7);
    n = n / 7;
    mul = mul * 10;
    dig++;
  }
  if (m != dig) s.insert(0);
  if (s.size() != m) return -1;
  long long int ans = 0;
  for (auto i : s) {
    ans = ans + ((1LL) << (i));
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n >> m;
  long long int dig1 = base7(max(1LL, n - 1));
  long long int dig2 = base7(max(1LL, m - 1));
  if ((dig1 + dig2) > 7) {
    cout << 0;
    return 0;
  }
  map<long long int, long long int> m1, m2;
  for (long long int i = 0; i < n; i++) {
    long long int x = getNo(i, dig1);
    if (x == -1) continue;
    m1[x]++;
  }
  for (long long int i = 0; i < m; i++) {
    long long int x = getNo(i, dig2);
    if (x == -1) continue;
    m2[x]++;
  }
  long long int count = 0;
  for (auto i : m1) {
    for (auto j : m2) {
      if (((i.first) & (j.first)) == 0) {
        count += (i.second) * (j.second);
      }
    }
  }
  cout << count;
  return 0;
}
