#include <bits/stdc++.h>
using namespace std;
int findlog(int n) {
  int ans = 0;
  int power = 1;
  while (power <= n) {
    power *= 7;
    ans++;
  }
  return ans;
}
string m1(int num, int a) {
  string ans;
  while (num) {
    int w = num % 7;
    num /= 7;
    ans = char(w + '0') + ans;
  }
  int l = ans.length();
  string temp;
  while (l < a) {
    temp += '0';
    l++;
  }
  ans = temp + ans;
  return ans;
}
bool checkall(string a, string b) {
  unordered_set<char> u;
  for (int i = 0; i < a.length(); i++) {
    if (u.find(a[i]) == u.end())
      u.insert(a[i]);
    else
      return false;
  }
  for (int i = 0; i < b.length(); i++) {
    if (u.find(b[i]) == u.end())
      u.insert(b[i]);
    else
      return false;
  }
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  int a = 1, b = 1;
  if (n != 1) a = findlog(n - 1);
  if (m != 1) b = findlog(m - 1);
  if (a + b > 7) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      string str = m1(i, a);
      string str1 = m1(j, b);
      if (checkall(str, str1)) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
