#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 7;
const long long maxe = 1e6 + 7;
const long long INF = 1e9 + 7;
const double PI = acos(-1);
int dx[4] = {0, 0, 1, -1};
int dy[4] = {-1, 1, 0, 0};
int n, m;
const int maxs = 5040;
int l1, l2;
int len(int x) {
  if (x == 0) return 1;
  int l = 0;
  while (x > 0) {
    l++;
    x /= 7;
  }
  return l;
}
bool vis[7];
int res = 0;
void dfs(int d1, int d2, int cn, int cm) {
  if (d1 == l1) {
    if (d2 == l2) {
      if (cm < m) res++;
    } else {
      for (int i = 0; i < 7; i++) {
        if (!vis[i]) {
          vis[i] = true;
          int ncm = cm * 7 + i;
          if (ncm < m) dfs(d1, d2 + 1, cn, ncm);
          vis[i] = false;
        }
      }
    }
  } else {
    for (int i = 0; i < 7; i++) {
      if (!vis[i]) {
        vis[i] = true;
        int ncn = cn * 7 + i;
        if (ncn < n) dfs(d1 + 1, d2, ncn, cm);
        vis[i] = false;
      }
    }
  }
}
int main() {
  cin >> n >> m;
  l1 = len(n - 1);
  l2 = len(m - 1);
  dfs(0, 0, 0, 0);
  cout << res << endl;
  return 0;
}
