#include <bits/stdc++.h>
using namespace std;
int n, m;
int len1, len2;
int num1, num2;
int Ans;
int b[12];
int cnt[12];
inline void getInfo(int &len, int x) {
  if (x == 0) len++;
  int tmp;
  while (x != 0) {
    len++;
    tmp = x % 7;
    x = x / 7;
  }
}
inline int toTen(int st, int ed) {
  int res = 0, t = 1;
  for (int i = st; i >= ed; i--) {
    res = res + t * b[i];
    t *= 7;
  }
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  n--;
  m--;
  getInfo(len1, n);
  getInfo(len2, m);
  if (len1 + len2 > 7) {
    printf("0\n");
    return 0;
  }
  int len = len1 + len2;
  while (b[0] == 0) {
    num1 = toTen(len1, 1);
    num2 = toTen(len, len1 + 1);
    if (num1 <= n && num2 <= m) {
      bool flag = true;
      memset(cnt, 0, sizeof(cnt));
      for (int i = 1; i <= len; i++) cnt[b[i]]++;
      for (int i = 0; i <= 6; i++)
        if (cnt[i] > 1) {
          flag = false;
          break;
        }
      if (flag) Ans++;
    }
    int j = len;
    while (b[j] == 6) {
      b[j] = 0;
      j--;
    }
    b[j]++;
  }
  printf("%d\n", Ans);
  return 0;
}
