#include <bits/stdc++.h>
using namespace std;
int bit(int a) {
  int b = 1;
  for (int i = 7; i < a; i *= 7) b++;
  return b;
}
int n, m, x, y, ans = 0, c[7];
int main() {
  cin >> n >> m;
  int len1 = bit(n), len2 = bit(m);
  if (bit(n) + bit(m) > 7) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      memset(c, 0, sizeof(c));
      x = i, y = j;
      for (int k = 0; k < len1; k++) {
        c[x % 7]++;
        x /= 7;
      }
      for (int k = 0; k < len2; k++) {
        c[y % 7]++;
        y /= 7;
      }
      int k = 0;
      for (k = 0; k < 7; k++) {
        if (c[k] > 1) break;
      }
      if (k >= 7) ans++;
    }
  }
  cout << ans;
  return 0;
}
