#include <bits/stdc++.h>
using namespace std;
string h = "", mm = "";
int arr[10];
string PlusOne(string s) {
  if (s.size() == 0) return "";
  s[s.size() - 1]++;
  int i = s.size() - 1;
  while (s[i] == '7') {
    s[i] = '0';
    i--;
    if (i >= 0) s[i]++;
  }
  return s;
}
int findPow(long long x) {
  int i = 1;
  long long a = 7;
  while (a < x) {
    a *= 7;
    i++;
  }
  return i;
}
string Zero(string x) {
  int size = x.size();
  x = "";
  for (int i = 0; i < size; i++) x += '0';
  return x;
}
bool check() {
  for (int i = 0; i < 7; i++) arr[i] = 0;
  for (int i = 0; i < h.size(); i++) arr[h[i] - '0']++;
  for (int i = 0; i < mm.size(); i++) arr[mm[i] - '0']++;
  for (int i = 0; i < 7; i++) {
    if (arr[i] > 1) return false;
  }
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  int count = 0;
  if (findPow(n) + findPow(m) > 7) {
    cout << 0;
    return 0;
  }
  for (int i = 1; i <= findPow(n); i++) h += '0';
  for (int i = 1; i <= findPow(m); i++) mm += '0';
  for (int i = 0; i < n; i++) {
    mm = Zero(mm);
    for (int j = 0; j < m; j++) {
      if (check()) count++;
      mm = PlusOne(mm);
    }
    h = PlusOne(h);
  }
  cout << count;
  return 0;
}
