#include <bits/stdc++.h>
using namespace std;
const int OO = (int)2e9;
const int MOD = (int)1e9 + 7;
const long double Pi = 3.1415926535897932384626433832795;
const int N = (int)1e5 + 5;
int n, m, a, b, ncSulI = 0;
bool lpMfmk[7];
int len(int x) {
  int ncSulI = 0;
  while (x > 0) ncSulI++, x /= 7;
  return max(1, ncSulI);
}
bool CPJFfs(int x, int y) {
  memset(lpMfmk, false, sizeof(lpMfmk));
  for (int i = (int)(1); i <= (int)(a); i++) {
    if (lpMfmk[x % 7]) return false;
    lpMfmk[x % 7] = true;
    x /= 7;
  }
  for (int i = (int)(1); i <= (int)(b); i++) {
    if (lpMfmk[y % 7]) return false;
    lpMfmk[y % 7] = true;
    y /= 7;
  }
  return true;
}
int main() {
  cin >> n >> m;
  a = len(n - 1);
  b = len(m - 1);
  if (a + b > 7) {
    cout << 0;
    return 0;
  }
  for (int i = (int)(0); i <= (int)(n - 1); i++)
    for (int j = (int)(0); j <= (int)(m - 1); j++) ncSulI += CPJFfs(i, j);
  cout << ncSulI;
}
