#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio;
  cin.tie(0);
  cout.tie(0);
  ;
  long long a, b;
  cin >> a >> b;
  a--;
  b--;
  long long aa = a, bb = b;
  long long hour = 0, min = 0;
  while (aa > 0) {
    aa /= 7;
    hour++;
  }
  while (bb > 0) {
    bb /= 7;
    min++;
  }
  a++;
  b++;
  hour = max(hour, 1LL);
  min = max(min, 1LL);
  if (hour + min > 7)
    cout << 0 << '\n';
  else {
    vector<long long> h, m, used;
    int ans = 0;
    for (int i = 0; i < a; i++) {
      for (int j = 0; j < b; j++) {
        h.assign(hour, 0);
        m.assign(min, 0);
        used.assign(7, 0);
        aa = i;
        bb = j;
        int pos_h = hour - 1, pos_m = min - 1;
        while (aa > 0) {
          h[pos_h] = aa % 7;
          aa /= 7;
          pos_h--;
        }
        while (bb > 0) {
          m[pos_m] = bb % 7;
          bb /= 7;
          pos_m--;
        }
        int check = 1;
        for (int x = 0; x < hour; x++) {
          used[h[x]]++;
        }
        for (int x = 0; x < min; x++) {
          used[m[x]]++;
        }
        for (int x = 0; x < 7; x++) {
          if (used[x] > 1) {
            check = 0;
          }
        }
        if (check == 1) ans++;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
