#include <bits/stdc++.h>
using namespace std;
const int qq = 100005;
int num[105];
int len1, len2;
bool f(int x, int y) {
  int a = len1 - 1;
  int aa[10], bb[10];
  memset(aa, 0, sizeof(aa));
  memset(bb, 0, sizeof(bb));
  if (x == 0) aa[a--] = 0;
  while (x) {
    aa[a--] = x % 7;
    x /= 7;
  }
  int b = len2 - 1;
  if (y == 0) bb[b--] = 0;
  while (y) {
    bb[b--] = y % 7;
    y /= 7;
  }
  int digit[7];
  memset(digit, 0, sizeof(digit));
  for (int i = 0; i < len1; ++i) digit[aa[i]]++;
  for (int i = 0; i < len2; ++i) digit[bb[i]]++;
  for (int i = 0; i < 7; ++i)
    if (digit[i] > 1) return false;
  return true;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  n--;
  m--;
  int cnt = 0;
  int a = n;
  int b = m;
  if (a == 0) num[cnt++] = 0;
  while (a) {
    num[cnt++] = a % 7;
    a /= 7;
  }
  len1 = cnt;
  if (b == 0) num[cnt++] = 0;
  while (b) {
    num[cnt++] = b % 7;
    b /= 7;
  }
  len2 = cnt - len1;
  if (cnt > 7) {
    printf("0\n");
    return 0;
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= m; ++j)
      if (f(i, j)) ans++;
  printf("%d\n", ans);
  return 0;
}
