#include <bits/stdc++.h>
using namespace std;
int n, m, ans = 0, l1 = 0, l2 = 0;
int f1(int x) {
  if (x == 1) return 1;
  int ans = 0;
  x--;
  while (x) {
    ans++, x /= 7;
  }
  return ans;
}
bool pd(int x, int y) {
  int x1 = x, y1 = y;
  int t;
  bool used[10];
  memset(used, 0, sizeof(used));
  if (x == 0 && y == 0) return 0;
  if (x == 0 || y == 0) used[0] = 1;
  while (x) {
    t = x % 7;
    if (!used[t])
      used[t] = 1;
    else
      return 0;
    x /= 7;
  }
  while (y) {
    t = y % 7;
    if (!used[t])
      used[t] = 1;
    else
      return 0;
    y /= 7;
  }
  t = 0;
  for (int i = 0; i < 7; i++) t += used[i];
  if (t == l1 + l2 || (t == l1 + l2 - 1 && used[0] == 0)) {
    return 1;
  }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  l1 = f1(n), l2 = f1(m);
  if (l1 + l2 > 7 || (n > 117649) || (m > 117649)) {
    printf("0");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans += pd(i, j);
    }
  }
  printf("%d", ans);
  return 0;
}
