#include <bits/stdc++.h>
long long int power(long long int x, long long int b) {
  long long int p = 1;
  while (b > 0) {
    if (b & 1) {
      p = p * x;
      p %= 9000000000000000000;
    }
    b >>= 1;
    x *= x;
    x %= 9000000000000000000;
  }
  return p % 9000000000000000000;
}
using namespace std;
struct lex_compare {
  bool operator()(const pair<long double, long long int> p1,
                  const pair<long double, long long int> p2) {
    return (p1.first == p2.first) ? p1.second < p2.second : p1.first > p2.first;
  }
};
long long int ans = 0;
void rec(string s, set<long long int> st, long long int i,
         long long int digits1, long long int digits2, long long int n,
         long long int m) {
  if (i == digits1 + digits2) {
    long long int first = 0, second = 0;
    for (long long int j = 0; j < digits1; j++) {
      first = (first * 7 + (long long int)(s[j] - '0'));
    }
    for (long long int j = digits1; j < i; j++) {
      second = (second * 7 + (long long int)(s[j] - '0'));
    }
    if (first < n && second < m) ans++;
    return;
  }
  for (auto j : st) {
    set<long long int> temps = st;
    temps.erase(j);
    string s1 = s;
    s1 += (char('0' + j));
    rec(s1, temps, i + 1, digits1, digits2, n, m);
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n, m;
  cin >> n >> m;
  set<long long int> s;
  for (long long int i = 0; i < 7; i++) s.insert(i);
  long long int digits1 = 0, digits2 = 0;
  long long int temp = max(n - 1, 1LL);
  while (temp) {
    temp /= 7;
    digits1++;
  }
  temp = max(m - 1, 1LL);
  while (temp) {
    temp /= 7;
    digits2++;
  }
  if (n <= 1 && m <= 1) {
    cout << 0 << "\n";
    return 0;
  }
  rec("", s, 0, digits1, digits2, n, m);
  cout << ans << "\n";
  return 0;
}
