#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int n, m, len1 = 1, len2 = 1, ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int a = 7; a < n; a *= 7) len1 += 1;
  for (int b = 7; b < m; b *= 7) len2 += 1;
  if (len1 + len2 <= 7) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        vector<int> used(7, 0);
        for (int a = i, k = 0; k < len1; a /= 7, k++) used[a % 7] += 1;
        for (int b = j, k = 0; k < len2; b /= 7, k++) used[b % 7] += 1;
        if (*max_element(used.begin(), used.end()) <= 1) ans++;
      }
  }
  cout << ans;
  return 0;
}
