#include <bits/stdc++.h>
int n, m, tn, tm, vis[7];
char mi[7], ho[7];
int val(char *x, int len) {
  int t = 0;
  for (int i = len - 1; i >= 0; --i) {
    t = t * 7 + x[i] - '0';
  }
  return t;
}
void add1() {
  int g = 1;
  for (int i = 0; i < tm; ++i) {
    mi[i] += g;
    if (mi[i] == '7')
      g = 1, mi[i] = '0';
    else
      g = 0;
  }
  if (val(mi, tm) >= m) memset(mi, '0', sizeof(mi)), g = 1;
  if (g)
    for (int i = 0; i < tn; ++i) {
      ho[i] += g;
      if (ho[i] == '7')
        g = 1, ho[i] = '0';
      else
        g = 0;
    }
}
bool cmp() {
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < tn; ++i) {
    if (vis[ho[i] - '0'])
      return false;
    else
      vis[ho[i] - '0'] = 1;
  }
  for (int i = 0; i < tm; ++i) {
    if (vis[mi[i] - '0'])
      return false;
    else
      vis[mi[i] - '0'] = 1;
  }
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  if (n == 1)
    tn = 1;
  else
    tn = log(n * 7.0 - 1) / log(7);
  if (m == 1)
    tm = 1;
  else
    tm = log(m * 7.0 - 1) / log(7);
  if (tn + tm > 7) {
    puts("0");
  } else {
    memset(ho, '0', sizeof(ho));
    memset(mi, '0', sizeof(mi));
    int en = n * m, ans = 0;
    for (int i = 0; i < en; ++i) {
      if (cmp()) ++ans;
      add1();
    }
    printf("%d\n", ans);
  }
  return 0;
}
