#include <bits/stdc++.h>
const int maxn = 110;
using namespace std;
string s1;
string s2;
int n, m;
int vis[10];
int ans = 0;
int lenh;
int lenm;
string tentoseven(int x) {
  string tmp = "";
  while (x) {
    int tmptmp = x % 7;
    tmp += tmptmp + '0';
    x /= 7;
  }
  reverse(tmp.begin(), tmp.end());
  return tmp;
}
void dfs(int deep, int falg) {
  if (deep == lenh + lenm) {
    ans++;
    return;
  }
  int mx = 6;
  if (falg) {
    mx = deep < lenm ? s2[deep] : s1[deep - lenm];
    mx -= '0';
  }
  for (int i = 0; i <= mx; i++) {
    int f = 1;
    if (!vis[i]) {
      if (deep < lenm - 1 || deep >= lenm) f = (falg && i == mx);
      vis[i] = 1;
      dfs(deep + 1, f);
      vis[i] = 0;
    }
  }
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    s1 = tentoseven(n - 1);
    s2 = tentoseven(m - 1);
    lenh = s1.size();
    lenm = s2.size();
    if (lenh == 0) {
      lenh++;
      s1 += '0';
    }
    if (lenm == 0) {
      lenm++;
      s2 += '0';
    }
    memset(vis, 0, sizeof(vis));
    ans = 0;
    dfs(0, 1);
    cout << ans << endl;
  }
}
