#include <bits/stdc++.h>
using namespace std;
long long a[10];
int main() {
  long long n, m, siz = 0, siz2 = 0, x, y, ans = 0;
  string s, s2;
  bool l;
  cin >> n >> m;
  x = n - 1;
  if (x == 0) siz++;
  while (x != 0) {
    x /= 7;
    siz++;
  }
  x = m - 1;
  if (x == 0) siz2++;
  while (x != 0) {
    x /= 7;
    siz2++;
  }
  if (siz + siz2 > 7) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < 7; k++) a[k] = 0;
      x = i;
      s = "";
      s2 = "";
      if (x == 0) s = (char)('0' + (x % 7)) + s;
      while (x != 0) {
        s = (char)('0' + (x % 7)) + s;
        x /= 7;
      }
      x = j;
      if (x == 0) s2 = (char)('0' + (x % 7)) + s2;
      while (x != 0) {
        s2 = (char)('0' + (x % 7)) + s2;
        x /= 7;
      }
      if (s.size() > siz || s2.size() > siz2) {
        continue;
      }
      y = s.size();
      for (int k = y; k < siz; k++) s = '0' + s;
      y = s2.size();
      for (int k = y; k < siz2; k++) s2 = '0' + s2;
      for (int k = 0; k < siz; k++) {
        a[s[k] - '0']++;
      }
      for (int k = 0; k < siz2; k++) {
        a[s2[k] - '0']++;
      }
      l = false;
      for (int k = 0; k < 7; k++) {
        if (a[k] > 1) {
          l = true;
        }
      }
      if (l == 0) ans++;
    }
  }
  cout << ans;
  return 0;
}
