#include <bits/stdc++.h>
using namespace std;
int n, m;
int nlog7, mlog7;
int A[1 << 7], B[1 << 7];
int cache[7];
const int KMAX = 823543;
bool go_n(int x) {
  for (int i = 0; i < 7; i++) cache[i] = 0;
  for (int i = 0; i < nlog7; i++) {
    cache[x % 7]++;
    x /= 7;
  }
  for (int i = 0; i < 7; i++)
    if (cache[i] >= 2) return false;
  int bit = 0;
  for (int i = 0; i < 7; i++)
    if (cache[i]) bit |= (1 << i);
  A[bit]++;
  return true;
}
bool go_m(int x) {
  for (int i = 0; i < 7; i++) cache[i] = 0;
  for (int i = 0; i < mlog7; i++) {
    cache[x % 7]++;
    x /= 7;
  }
  for (int i = 0; i < 7; i++)
    if (cache[i] >= 2) return false;
  int bit = 0;
  for (int i = 0; i < 7; i++)
    if (cache[i]) bit |= (1 << i);
  B[bit]++;
  return true;
}
int main() {
  scanf("%d%d", &n, &m);
  n--, m--;
  int t = n;
  if (t == 0)
    nlog7 = 1;
  else {
    while (t > 0) nlog7++, t /= 7;
  }
  t = m;
  if (t == 0)
    mlog7 = 1;
  else {
    while (t > 0) mlog7++, t /= 7;
  }
  for (int i = 0; i < KMAX; i++) {
    if (i > n) break;
    go_n(i);
  }
  for (int i = 0; i < KMAX; i++) {
    if (i > m) break;
    go_m(i);
  }
  long long ans = 0;
  for (int i = 0; i < (1 << 7); i++) {
    for (int j = 0; j < (1 << 7); j++) {
      if ((i & j) == 0) {
        ans += (long long)A[i] * B[j];
      }
    }
  }
  printf("%lld", ans);
}
