#include <bits/stdc++.h>
using namespace std;
int g[10];
bool b[10];
int i, j, k, l, m, n, r, s, t, tt, ttt;
int main() {
  scanf("%d%d", &n, &m);
  for (k = n - 1; k > 0; k = k / 7) tt++;
  if (n == 1) tt++;
  for (k = m - 1, t = tt; k > 0; k = k / 7) t++;
  if (m == 1) t++;
  if ((t > 7) || ((n == 1) && (m == 1))) {
    printf("0");
    return 0;
  }
  for (i = 1; i <= t; i++) g[i] = i - 1;
  ttt = 1;
  for (i = 1; i <= t; i++) ttt = ttt * 7;
  for (i = 1; i <= ttt; i++) {
    r = 1;
    memset(b, false, sizeof(b));
    for (j = 1; j <= t; j++)
      if (!b[g[j]])
        b[g[j]] = true;
      else
        r = 0;
    for (k = 1, l = 0; k <= tt; k++) l = l * 7 + g[k];
    if (l >= n) r = 0;
    for (k = tt + 1, l = 0; k <= t; k++) l = l * 7 + g[k];
    if (l >= m) r = 0;
    s = s + r;
    g[t]++;
    for (j = t; j > 0; j--)
      if (g[j] == 7) g[j] = 0, g[j - 1]++;
  }
  printf("%d", s);
  return 0;
}
