#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
long long n, m;
int freq[10];
bool vis[10];
vector<string> ms;
long long mx = 0;
int ans;
int d;
void generate1(string s) {
  if (s.size() == d && mx >= stoll(s)) {
    if (stoll(s) > mx) return;
    ms.push_back(s);
    return;
  }
  for (int i = 0; i < 7; i++) {
    if (vis[i]) continue;
    vis[i] = 1;
    generate1(s + to_string(i));
    vis[i] = 0;
  }
}
void generate2(string s) {
  if (s.size() == d && mx >= stoll(s)) {
    for (int i = 0; i < ms.size(); i++) {
      bool add = 1;
      for (int k = 0; k < ms[i].size(); k++)
        for (int j = 0; j < s.size(); j++)
          if (s[j] == ms[i][k]) add = 0;
      ans += add;
    }
    return;
  }
  for (int i = 0; i < 7; i++) {
    if (vis[i]) continue;
    vis[i] = 1;
    generate2(s + to_string(i));
    vis[i] = 0;
  }
}
int main() {
  scanf("%lld%lld", &n, &m);
  n--;
  m--;
  long long tmp = m, p = 1;
  while (tmp != 0) {
    mx = mx + (tmp % 7) * p;
    p *= 10;
    tmp /= 7;
  }
  d = log10((mx == 0 ? 1 : mx)) + 1;
  generate1("");
  mx = 0, tmp = n, p = 1;
  while (tmp != 0) {
    mx = mx + (tmp % 7) * p;
    p *= 10;
    tmp /= 7;
  }
  d = log10((mx == 0 ? 1 : mx)) + 1;
  generate2("");
  cout << ans;
}
