#include <bits/stdc++.h>
using namespace std;
int p7[10];
int main(void) {
  int n, m, i;
  p7[0] = 1;
  for (i = 1; i < 10; i++) p7[i] = p7[i - 1] * 7;
  p7[0] = 0;
  while (scanf(" %d %d", &n, &m) != EOF) {
    int kh, km;
    for (kh = 0; kh < 8; kh++) {
      if (p7[kh] >= n) break;
    }
    for (km = 0; km < 8; km++) {
      if (p7[km] >= m) break;
    }
    if (kh + km >= 8) {
      printf("0\n");
      continue;
    }
    int res = 0;
    int i, j, i1, j1, ti, tj, u[8] = {0};
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++) {
        ti = i;
        tj = j;
        memset(u, 0, sizeof(u));
        for (i1 = 0; i1 < kh; i1++) {
          u[ti % 7]++;
          ti /= 7;
        }
        for (j1 = 0; j1 < km; j1++) {
          u[tj % 7]++;
          tj /= 7;
        }
        for (i1 = 0; i1 < 7; i1++)
          if (u[i1] > 1) break;
        if (i1 == 7) res++;
      }
    cout << res << endl;
  }
  return 0;
}
