#include <bits/stdc++.h>
using namespace std;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return n & two(b); }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
int n, m, rn, rm, vis[8];
int check(int x, int p) {
  for (int i = 0; i < p; i++) {
    int dig = x % 7;
    if (vis[dig]) return 0;
    vis[dig] = 1;
    x /= 7;
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  if (n == 1)
    rn = 1;
  else
    for (int i = 1; i <= (n - 1); i *= 7) rn++;
  if (m == 1)
    rm = 1;
  else
    for (int i = 1; i <= (m - 1); i *= 7) rm++;
  if (rn + rm > 7) {
    cout << 0 << '\n';
    return 0;
  }
  long long ans = 0ll;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      memset(vis, (0), sizeof(vis));
      if (check(i, rn) and check(j, rm)) {
        ans++;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
