#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > a;
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  int i, j, i2;
  int s[7] = {0, 1, 2, 3, 4, 5, 6};
  int n2 = n - 1, cntn = 0;
  while (n2) {
    cntn++;
    n2 = n2 / 7;
  }
  int m2 = m - 1, cntm = 0;
  while (m2) {
    cntm++;
    m2 = m2 / 7;
  }
  if (cntm + cntn > 7) {
    printf("0\n");
    return 0;
  }
  do {
    for (i = 0; i < 6; i++)
      for (j = i + 1; j < 7; j++) {
        int nn = 0, mm = 0;
        string aa = "", bb = "";
        for (i2 = 0; i2 <= i; i2++) nn = nn * 7 + s[i2], aa += to_string(s[i2]);
        for (i2 = i + 1; i2 <= j; i2++)
          mm = mm * 7 + s[i2], bb += to_string(s[i2]);
        if (nn < n && mm < m) {
          for (i2 = i + 1; i2 < cntn; i2++) aa = "0" + aa;
          for (i2 = j - i; i2 < cntm; i2++) bb = "0" + bb;
          int zr = 0;
          for (i2 = 0; i2 < aa.length(); i2++)
            if (aa[i2] == '0') zr++;
          for (i2 = 0; i2 < bb.length(); i2++)
            if (bb[i2] == '0') zr++;
          if (zr <= 1) {
            a.insert(make_pair(nn, mm));
          }
        }
      }
  } while (next_permutation(s, s + 7));
  printf("%d\n", a.size());
  return 0;
}
