#include <bits/stdc++.h>
const double eps = 1e-10;
const float epsf = 1e-6;
using namespace std;
inline long long int __gcd(long long int a, long long int b) {
  if (a == 0 || b == 0) {
    return max(a, b);
  }
  long long int tempa, tempb;
  while (1) {
    if (a % b == 0)
      return b;
    else {
      tempa = a;
      tempb = b;
      a = tempb;
      b = tempa % tempb;
    }
  }
}
inline int compfloat(float& x, float& y) {
  if (fabs(x - y) < epsf)
    return 0;
  else if (x - y > 0)
    return 1;
  return -1;
}
inline int compdouble(double x, double y) {
  if (fabs(x - y) < eps)
    return 0;
  else if (x - y > 0)
    return 1;
  else
    return -1;
}
bool prime(long long int k) {
  for (long long int i = 2; i * i <= k; i++)
    if (k % i == 0) {
      return false;
    }
  return true;
}
void pdash(int n = 1) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 30; j++) {
      cout << "-";
    }
    cout << "\n";
  }
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  int len1 = 1, len2 = 1;
  for (long long int a = 7; a < n; a *= 7) len1++;
  for (long long int a = 7; a < m; a *= 7) len2++;
  long long int ans = 0;
  if (len1 + len2 <= 7) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        vector<int> vec(7, 0);
        for (int a = i, k = 0; k < len1; a /= 7, k++) vec[a % 7]++;
        for (int b = j, k = 0; k < len2; b /= 7, k++) vec[b % 7]++;
        if (*max_element(vec.begin(), vec.end()) <= 1) ans++;
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
