#include <bits/stdc++.h>
volatile bool isLocalTestEnabled = 0;
bool g_isLocalPrintEnabled = (bool)(0);
template <typename T>
void UpdateMin(T& a, const T b) {
  a = std::min(a, b);
}
template <typename T>
void UpdateMax(T& a, const T b) {
  a = std::max(a, b);
}
const long double Pi = std::atan(1.0L) * 4.0L;
static const long double Eps = 1.0e-09;
template <typename T>
bool IsEqual(const T a, const T b) {
  return std::abs(a - b) < Eps;
}
template <typename T>
bool IsGreater(const T a, const T b) {
  return a > b + Eps;
}
template <typename T>
bool IsLess(const T a, const T b) {
  return a + Eps < b;
}
template <typename T>
bool IsGreaterEqual(const T a, const T b) {
  return !IsLess(a, b);
}
template <typename T>
bool IsLessEqual(const T a, const T b) {
  return !IsGreater(a, b);
}
template <typename T>
std::string ToStr(const T& val) {
  std::ostringstream ostr;
  ostr << val;
  return ostr.str();
}
template <typename T>
bool FromStr(const std::string& str, T& val) {
  std::istringstream istr(str);
  istr >> val;
  return !!istr;
}
template <typename T>
std::istream& operator>>(std::istream& ist, std::vector<T>& data) {
  ;
  for (size_t i = 0; i < data.size(); i++) {
    ist >> data[i];
  }
  return ist;
}
template <typename T>
T Read(std::istream& ist) {
  ;
  T val;
  ist >> val;
  return val;
}
template <typename T>
std::ostream& operator<<(std::ostream& ost, const std::vector<T>& data) {
  for (size_t i = 0; i < data.size(); i++) {
    if (i != 0) {
      ost << ' ';
    }
    ost << data[i];
  }
  return ost;
}
template <size_t id>
class StopWatch {};
const uint32_t Base = 7;
uint32_t GetMaxMask(const size_t len) {
  uint32_t p = 1;
  for (size_t i = 1; i <= len; i++) {
    p *= Base;
  }
  return p;
}
std::vector<uint32_t> GetDigits(uint32_t v, const uint32_t vLen) {
  std::vector<uint32_t> digits(vLen);
  for (size_t i = 0; i < vLen; i++) {
    digits[vLen - i - 1] = v % Base;
    v /= Base;
  }
  return digits;
}
uint32_t DigitsCount(const uint32_t z) {
  if (z == 0) return 1;
  uint32_t c = z;
  uint32_t ans = 0;
  while (c != 0) {
    c /= Base;
    ans++;
  }
  return ans;
}
uint32_t ToValue(const std::vector<uint32_t>& digits, const size_t b,
                 const size_t e) {
  uint32_t v = 0;
  for (size_t i = b; i < e; i++) {
    v *= Base;
    v += digits[i];
  }
  return v;
}
void GetVariants(const uint32_t n, const uint32_t m, const uint32_t nLen,
                 const uint32_t mLen, const uint32_t len, const uint32_t mask,
                 std::set<std::pair<uint32_t, uint32_t> >& vars) {
  std::vector<uint32_t> digits;
  uint32_t rmask = mask;
  for (size_t i = 0; i < len; i++) {
    const uint32_t d = rmask % Base;
    digits.push_back(d);
    rmask /= Base;
  }
  std::reverse(digits.begin(), digits.end());
  const size_t zerosCount = std::count(digits.begin(), digits.end(), 0);
  if (zerosCount > 1) return;
  std::set<uint32_t> allDigits(digits.begin(), digits.end());
  if (allDigits.size() != digits.size()) return;
  for (size_t firstLen = 1; firstLen < len; firstLen++) {
    const size_t secondLen = len - firstLen;
    if (firstLen > nLen) continue;
    if (secondLen > mLen) continue;
    const uint32_t x = ToValue(digits, 0, firstLen);
    const uint32_t y = ToValue(digits, firstLen, len);
    if (x >= n) continue;
    if (y >= m) continue;
    vars.insert(std::pair<uint32_t, uint32_t>(x, y));
  }
}
bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode) {
  StopWatch<1> sw;
  (void)sw;
  uint32_t n, m;
  ist >> n >> m;
  if (multipleTestMode && !ist) return false;
  if (!g_isLocalPrintEnabled) {
  } else
    std::cerr << std::endl << "Next test: " << n << ' ' << m << std::endl;
  const size_t nLen = DigitsCount(n - 1);
  const size_t mLen = DigitsCount(m - 1);
  std::set<std::pair<uint32_t, uint32_t> > vars;
  for (uint32_t len = nLen + mLen; len <= Base; len++) {
    const uint32_t MaxMask = GetMaxMask(len);
    for (uint32_t mask = 0; mask < MaxMask; mask++) {
      GetVariants(n, m, nLen, mLen, len, mask, vars);
    }
  }
  const size_t ans = vars.size();
  ost << ans << std::endl;
  return multipleTestMode;
}
int main(int argc, const char* argv[]) {
  std::ios_base::sync_with_stdio(false);
  std::istream* ist = &std::cin;
  std::ostream* ost = &std::cout;
  std::unique_ptr<std::istream> fileInput;
  if (argc > 1) {
    fileInput.reset(new std::ifstream(argv[1]));
    if (!(*fileInput)) {
      std::cout << "File not found: " << argv[1] << std::endl;
    }
    ist = fileInput.get();
  }
  Solve(*ist, *ost, false);
}
