#include <bits/stdc++.h>
using namespace std;
long long n, m, tmp1, tmp2, sum(1), a[8], dp[8], jum, ans(1), d, e, answer;
bitset<10> b;
bool bb;
vector<vector<long long> > v, w;
vector<long long> z;
void permutasi1(long long x) {
  if (x == ans) {
    long long jum = 0;
    for (int i = 0; i < ans; i++) {
      jum *= 7;
      jum += a[i];
    }
    if (jum < n) {
      vector<long long> z;
      for (int i = 0; i < ans; i++) {
        z.push_back(a[i]);
      }
      v.push_back(z);
    }
  } else {
    for (int i = 0; i <= 6; i++) {
      if (b[i] == false) {
        b[i] = true;
        a[x] = i;
        permutasi1(x + 1);
        b[i] = false;
      }
    }
  }
}
void permutasi2(long long x) {
  if (x == sum) {
    long long jum = 0;
    for (int i = 0; i < sum; i++) {
      jum *= 7;
      jum += a[i];
    }
    if (jum < m) {
      vector<long long> z;
      for (int i = 0; i < sum; i++) {
        z.push_back(a[i]);
      }
      w.push_back(z);
    }
  } else {
    for (int i = 0; i <= 6; i++) {
      if (b[i] == false) {
        b[i] = true;
        a[x] = i;
        permutasi2(x + 1);
        b[i] = false;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  tmp1 = n - 1;
  while (tmp1 >= 7) {
    ans++;
    tmp1 /= 7;
  }
  permutasi1(0);
  tmp2 = m - 1;
  while (tmp2 >= 7) {
    sum++;
    tmp2 /= 7;
  }
  permutasi2(0);
  if (ans + sum > 7) {
    cout << 0 << '\n';
    return 0;
  }
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < w.size(); j++) {
      z = v[i];
      bb = false;
      for (int i = 0; i <= 6; i++) {
        dp[i] = 0;
      }
      for (int k = 0; k < ans; k++) {
        dp[z[k]]++;
      }
      z = w[j];
      for (int k = 0; k < sum; k++) {
        dp[z[k]]++;
      }
      for (int k = 0; k <= 6; k++) {
        if (dp[k] >= 2) {
          bb = true;
          break;
        }
      }
      if (bb == false) {
        answer++;
      }
    }
  }
  cout << answer << '\n';
}
