#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T a, T b = 0) {
  if (b == 0) return (a < 0) ? -a : a;
  return (a > b) ? (a - b) : (b - a);
}
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline long long pow(T a, T b) {
  if (b == 1) return a;
  long long t = pow(a, b / 2);
  t *= t;
  if (!(b % 2)) return t;
  return a * t;
}
bool pali(string temp, int i, int j) {
  if (i >= j) return true;
  if (temp[i] == temp[j]) return pali(temp, i + 1, j - 1);
  return false;
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &printf) {
  return os << "(" << printf.first << ", " << printf.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  typename vector<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ",";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  typename set<T>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ",";
    os << *it;
  }
  return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
  os << "[";
  typename map<F, S>::const_iterator it;
  for (it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ",";
    os << it->first << "=" << it->second;
  }
  return os << "]";
}
int coun1, coun2;
int test(int x, int y) {
  int fre[10];
  memset(fre, 0, sizeof(fre));
  for (int i = 0; i < coun1; i++) {
    if (!fre[x % 7])
      fre[x % 7] = 1;
    else
      return 0;
    x /= 7;
  }
  for (int i = 0; i < coun2; i++) {
    if (!fre[y % 7])
      fre[y % 7] = 1;
    else
      return 0;
    y /= 7;
  }
  return 1;
}
int call(int n, int m) {
  int _n = n, _m = m;
  coun1 = coun2 = 0;
  if (n == 0) coun1 = 1;
  if (m == 0) coun2 = 1;
  while (n) {
    coun1++;
    n /= 7;
  }
  while (m) {
    coun2++;
    m /= 7;
  }
  if (coun1 + coun2 > 7) return 0;
  n = _n;
  m = _m;
  int coun = 0;
  for (int i = 0; i < n + 1; i++)
    for (int j = 0; j < m + 1; j++) {
      if (test(i, j)) coun++;
    }
  return coun;
}
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  cout << call(n - 1, m - 1) << endl;
  return 0;
}
