#include <bits/stdc++.h>
using namespace std;
int rec[2][8];
int pattern[2][5500];
int n1, n2, z;
int modpow(int n, int ex) {
  int res = 1;
  while (ex > 0) {
    if (ex % 2 == 1) res = (res * n) % 1000000007;
    n = (n * n) % 1000000007;
    ex = ex / 2;
  }
  return res;
}
void solve(int i) {
  if (i == (n1 + n2)) {
    int num = 0;
    for (int j = (0); j < (n1); j++) {
      num = num + (modpow(10, j)) * rec[0][j];
    }
    pattern[0][z] = num;
    num = 0;
    for (int j = (n1); j < (i); j++) {
      num = num + (modpow(10, j - n1)) * rec[0][j];
    }
    pattern[1][z] = num;
    z++;
    return;
  }
  for (int j = (0); j < (7); j++) {
    if (!rec[1][j]) {
      rec[1][j] = 1;
      rec[0][i] = j;
      solve(i + 1);
      rec[1][j] = 0;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, a = 0, b = 0, ten = 1, ans = 0;
  cin >> n >> m;
  int temp = n - 1;
  while (temp) {
    a += ten * (temp % 7);
    ten *= 10;
    temp /= 7;
    n1++;
  }
  ten = 1;
  temp = m - 1;
  while (temp) {
    b += ten * (temp % 7);
    ten *= 10;
    temp /= 7;
    n2++;
  }
  if (n1 == 0) n1 = 1;
  if (n2 == 0) n2 = 1;
  solve(0);
  if (n1 + n2 > 7) {
    cout << "0" << endl;
  } else {
    for (int i = (0); i < (z); i++) {
      if (pattern[0][i] <= a && pattern[1][i] <= b) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}
