#include <bits/stdc++.h>
using namespace std;
class TaskA {
 public:
  template <typename T>
  int from_string(T b, T e) {
    int res = 0;
    for (T x = b; x != e; ++x) {
      res *= 7;
      res += *x - '0';
    }
    return res;
  }
  string my_to_string(int a) {
    if (a == 0) {
      return "0";
    }
    string res;
    while (a) {
      res += char('0' + a % 7);
      a /= 7;
    }
    return res;
  }
  void solve(std::istream& in, std::ostream& out) {
    int n, m;
    in >> n >> m;
    int l = (int)my_to_string(n - 1).size();
    int r = (int)my_to_string(m - 1).size();
    int need = (int)(l + r);
    if (need > 7) {
      out << 0;
      return;
    }
    string s = "0123456";
    int64_t ans = 0;
    do {
      if (from_string(s.begin(), s.begin() + l) < n &&
          from_string(s.begin() + l, s.begin() + need) < m) {
        ++ans;
      }
    } while (next_permutation(s.begin(), s.end()));
    for (int i = 1; i <= 7 - need; ++i) {
      ans /= i;
    }
    out << ans;
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  TaskA solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  in.tie(0);
  out << std::fixed;
  out.precision(20);
  solver.solve(in, out);
  return 0;
}
