#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1e18;
long long a[2];
long long num[2][1 << 10];
long long sum = 0;
int main() {
  for (int i = 0; i < 2; i++) {
    cin >> a[i];
    long long d = 1;
    long long factor = 1;
    while (a[i] > factor * 7) {
      factor *= 7;
      d++;
    }
    sum += d;
    if (sum > 7) continue;
    for (long long j = 0; j < a[i]; j++) {
      int bits = 0;
      long long copy = j;
      for (long long t = 0; t < d; t++) {
        bits |= 1 << (copy % 7);
        copy /= 7;
      }
      if (__builtin_popcount(bits) != d) continue;
      num[i][bits]++;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < (1 << 10); i++) {
    for (long long j = 0; j < (1 << 10); j++) {
      if (i & j) continue;
      ans += num[0][i] * num[1][j];
    }
  }
  cout << ans << "\n";
  return 0;
}
