#include <bits/stdc++.h>
template <typename T>
using Vector2D = std::vector<std::vector<T>>;
template <typename T>
using Vector3D = std::vector<Vector2D<T>>;
using PairInt = std::pair<int, int>;
using PairInt64 = std::pair<int64_t, int64_t>;
using MapInt = std::map<int, int>;
using MMapInt = std::multimap<int, int>;
using MMapInt64 = std::multimap<int64_t, int64_t>;
using UMapIntString = std::unordered_map<int, std::string>;
using SetInt = std::set<int>;
using SetInt64 = std::set<int64_t>;
using SetPairInt64 = std::set<PairInt64>;
using VectorInt = std::vector<int>;
using VectorInt2D = Vector2D<int>;
using VectorInt64 = std::vector<int64_t>;
using VectorUInt64 = std::vector<uint64_t>;
using VectorInt642D = Vector2D<int64_t>;
using VectorChar = std::vector<char>;
using VectorChar2D = Vector2D<char>;
using VectorString = std::vector<std::string>;
using QueuePairInt = std::queue<PairInt>;
using QueueInt = std::queue<int>;
using VectorPairInt = std::vector<PairInt>;
using VectorPairInt64 = std::vector<PairInt64>;
using VectorPairInt2D = Vector2D<PairInt>;
using SetInt = std::set<int>;
using MSetInt = std::multiset<int>;
using UMapChar = std::map<char, int>;
using ListInt = std::list<int>;
using VectorListInt = std::vector<ListInt>;
using VectorDouble = std::vector<double>;
int from_7(const std::string& s) {
  int len = s.length();
  int rr = 1;
  int ret = 0;
  for (int i = len - 1; i >= 0; --i) {
    ret = ret + (s[i] - '0') * rr;
    rr *= 7;
  }
  return ret;
}
VectorString get_perms(const std::string& vals, int n) {
  if (n == 1) {
    return {vals.substr(0, 1)};
  }
  VectorString perms_prev = get_perms(vals, n - 1);
  VectorString perms;
  for (const auto& pp : perms_prev) {
    for (int i = 0; i < n; ++i) {
      perms.push_back(pp.substr(0, i) + vals[n - 1] + pp.substr(i));
    }
  }
  return perms;
}
std::string next_s(VectorInt& poss, const std::string& vals) {
  int maxp = vals.size() - 1;
  int last = poss.size() - 1;
  int i = last;
  while (i >= 0 && poss[i] >= maxp - (last - i)) --i;
  if (i < 0) return "";
  ++poss[i];
  for (++i; i <= last; ++i) poss[i] = poss[i - 1] + 1;
  std::string s;
  for (auto pos : poss) {
    s += vals[pos];
  }
  return s;
}
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  int m;
  std::cin >> n >> m;
  int rn = 0;
  for (int nn = n - 1; nn > 0; nn = nn / 7) ++rn;
  int rm = 0;
  for (int mm = m - 1; mm > 0; mm = mm / 7) ++rm;
  if (n == 1) rn = 1;
  if (m == 1) rm = 1;
  if (rn + rm > 7) {
    std::cout << "0";
    return 0;
  }
  std::string vals = "0123456";
  VectorInt poss(rn + rm);
  for (int i = 0; i < rn + rm; ++i) poss[i] = i;
  --poss.back();
  int ans = 0;
  while (1) {
    auto s = next_s(poss, vals);
    if (s.empty()) break;
    auto ppp = get_perms(s, s.length());
    for (const auto& p : ppp) {
      auto sn = from_7(p.substr(0, rn));
      auto sm = from_7(p.substr(rn));
      if (sn < n && sm < m) ++ans;
    }
  }
  std::cout << ans;
  return 0;
}
