#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int stala = 1e6;
unsigned n, m, logn, logm;
bool enough = false;
unsigned pow7[10];
bool check_dist(unsigned x, unsigned y) {
  if (y > m + 1) enough = 1;
  if (x > n || y > m) {
    return 0;
  }
  bool tab[7];
  memset(tab, 0, 7);
  for (unsigned i = 0; i < logn; i++, x /= 7)
    if (tab[x % 7]) {
      return 0;
    } else
      tab[x % 7] = 1;
  for (unsigned i = 0; i < logm; i++, y /= 7)
    if (tab[y % 7]) {
      return 0;
    } else
      tab[y % 7] = 1;
  return 1;
}
string seven(int x) {
  string res = "";
  for (unsigned i = 0; i < logn + logm; x /= 7, i++) {
    if (i == logn) res = '|' + res;
    res = (char)((x % 7) + '0') + res;
  }
  return res;
}
int32_t main() {
  ios::sync_with_stdio(0);
  pow7[0] = 1;
  for (int i = 0; i < 9; ++i) pow7[i + 1] = pow7[i] * 7;
  cin >> n >> m;
  n--;
  m--;
  if (n < m) swap(n, m);
  for (int i = n; i > 0; i /= 7, logn++)
    ;
  for (int i = m; i > 0; i /= 7, logm++)
    ;
  cerr << logn << " " << logm << "\n";
  logn = max(logn, 1u);
  logm = max(logm, 1u);
  if (logn + logm > 7 || logn + logm == 0) {
    cout << "0\n";
  } else {
    int il = 0;
    for (unsigned i = 0; !enough; i++) {
      auto tmp = check_dist(i % pow7[logn], i / pow7[logn]);
      if (tmp) {
      }
      il += tmp;
    }
    cout << il << "\n";
  }
  return 0;
}
