#include <bits/stdc++.h>
using namespace std;
int n, m;
int res;
void go(int x, int y, int mask, int cur1, int cur2) {
  if (x == 0 && y == 0) {
    if (cur1 <= n && cur2 <= m) res++;
    return;
  }
  for (int i = 0; i < 7; i++) {
    if (!((mask >> i) & 1)) {
      go((x > 0) ? (x - 1) : x, (x == 0) ? (y - 1) : y, mask | (1 << i),
         (x > 0) ? (cur1 * 7 + i) : cur1, (x == 0) ? (cur2 * 7 + i) : cur2);
    }
  }
}
int main() {
  cin >> n >> m;
  n--;
  m--;
  int n2 = n, m2 = m;
  int x = 0, y = 0;
  while (n2 > 0) {
    n2 /= 7;
    x++;
  }
  while (m2 > 0) {
    m2 /= 7;
    y++;
  }
  x = max(x, 1);
  y = max(y, 1);
  if (x + y <= 7) {
    go(x, y, 0, 0, 0);
  }
  cout << res << endl;
  return 0;
}
