#include <bits/stdc++.h>
using namespace std;
const int SIZE = 10;
const long long int MOD = (int)1e9 + 7;
const int MAXM = 2000;
const int STRSIZE = 10;
const int INF = (int)1e9 + 7;
const long double PI = acosl(-1);
int a[1 << 8][50], b[1 << 8][50];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  n--;
  m--;
  string s1, s2;
  if (n == 0) s1 = "0";
  while (n > 0) {
    s1 += n % 7 + '0';
    n /= 7;
  }
  if (m == 0) s2 = "0";
  while (m > 0) {
    s2 += m % 7 + '0';
    m /= 7;
  }
  string s = s1 + s2;
  if (s.size() > 7) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> a(7);
  iota(a.begin(), a.end(), 0);
  int cnt = 0;
  do {
    bool f = true;
    int i;
    for (i = s1.size() - 1; i >= 0; i--)
      if (s1[i] - '0' < a[i])
        f = false;
      else if (s[i] - '0' > a[i])
        break;
    for (i = s.size() - 1; i >= s1.size(); i--)
      if (s2[i - s1.size()] - '0' < a[i])
        f = false;
      else if (s2[i - s1.size()] - '0' > a[i])
        break;
    if (f)
      cnt++;
    else
      int t = 1;
    sort(a.begin() + s.size(), a.end(), greater<int>());
  } while (next_permutation(a.begin(), a.end()));
  cout << cnt << endl;
}
