#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 7;
const int M = 2e6 + 7;
const int lim = 1e6;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
int fun(int x) {
  if (x > 117649) return 7;
  if (x > 16807) return 6;
  if (x > 2401) return 5;
  if (x > 343) return 4;
  if (x > 49) return 3;
  if (x > 7) return 2;
  return 1;
}
bool solve(int x, int y, int xx, int yy) {
  int a[7] = {0, 0, 0, 0, 0, 0, 0};
  while (xx--) {
    if (a[x % 7]) return 0;
    a[x % 7]++;
    x /= 7;
  }
  while (yy--) {
    if (a[y % 7]) return 0;
    a[y % 7]++;
    y /= 7;
  }
  return 1;
}
int main() {
  int n, m, sum = 0;
  scanf("%d%d", &n, &m);
  if (n < m) swap(n, m);
  int xx = fun(n), yy = fun(m);
  if (xx + yy <= 7) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (solve(i, j, xx, yy)) sum++;
  }
  printf("%d\n", sum);
  return 0;
}
