#include <bits/stdc++.h>
using namespace std;
map<int, int> b;
long long power(int a, int b) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) x *= y;
    y = (y * y);
    b /= 2;
  }
  return x;
}
long long convert(int n) {
  long long c = 0, ans = 0;
  while (n > 0) {
    ans += (power(10, c) * (n % 7));
    n /= 7;
    c++;
  }
  return ans;
}
int log7(int n) {
  int c = 1;
  while (n >= 7) {
    n /= 7;
    c++;
  }
  return c;
}
int main() {
  int c = 0, n, m;
  cin >> n >> m;
  if (log7(n - 1) + log7(m - 1) <= 7) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        b.clear();
        b[0] += log7(n - 1) - log7(i);
        long long n1 = convert(i);
        while (n1 > 0) {
          b[n1 % 10]++;
          n1 /= 10;
        }
        if (i == 0) b[0]++;
        bool flag = false;
        b[0] += log7(m - 1) - log7(j);
        long long m1 = convert(j);
        while (m1 > 0) {
          b[m1 % 10]++;
          m1 /= 10;
        }
        if (j == 0) b[0]++;
        for (auto it = b.begin(); it != b.end(); it++) {
          if (it->second > 1) flag = true;
        }
        if (flag == false) c++;
      }
    }
  }
  cout << c << endl;
  return 0;
}
