#include <bits/stdc++.h>
using namespace std;
const int NAX = int(1e5), MOD = int(1e9 + 7), POW = int(53);
int n, m, ans;
map<int, bool> used;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  int b1 = 1, b2 = 1;
  for (int t = 7; t < n; t *= 7, b1++) {
  }
  for (int t = 7; t < m; t *= 7, b2++) {
  }
  if (b1 + b2 >= 8) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      used.clear();
      int ok = 1;
      for (int k = i, t = 1; t <= b1; k /= 7, t++)
        if (used[k % 7])
          ok = 0;
        else
          used[k % 7] = 1;
      for (int k = j, t = 1; t <= b2; k /= 7, t++)
        if (used[k % 7])
          ok = 0;
        else
          used[k % 7] = 1;
      ans += ok;
    }
  cout << ans;
  return 0;
}
