#include <bits/stdc++.h>
using namespace std;
int n, m, k1, k2, t, a[10], ans;
bool used[10];
bool chk() {
  int i = 0, c1 = 0, c2 = 0;
  for (; i < k1; i++) c1 = c1 * 7 + a[i];
  for (; i < k1 + k2; i++) c2 = c2 * 7 + a[i];
  return (c1 < n && c2 < m);
}
void dfs(int pos) {
  if (pos == k1 + k2 && chk()) ans++;
  for (int i = (0), _b = (6); i <= _b; ++i)
    if (!used[i]) {
      a[pos] = i, used[i] = true;
      dfs(pos + 1);
      used[i] = false;
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (t = 7, k1 = 1; t < n; t *= 7, k1++)
    ;
  for (t = 7, k2 = 1; t < m; t *= 7, k2++)
    ;
  if (k1 + k2 > 7) {
    printf("0");
    return 0;
  }
  dfs(0);
  printf("%d", ans);
  return 0;
}
