#include <bits/stdc++.h>
using namespace std;
bool vis[10];
bool judge(int x, int len) {
  int sum = 0;
  while (x) {
    if (vis[x % 7]) {
      return 0;
    }
    vis[x % 7] = 1;
    x /= 7;
    sum++;
  }
  for (int i = sum; i < len; i++) {
    if (vis[0] == 1) return 0;
    vis[0] = 1;
  }
  return 1;
}
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  int ans = 0;
  int len1 = 1;
  int len2 = 1;
  for (int i = 7; i < n; i *= 7) len1++;
  for (int i = 7; i < m; i *= 7) len2++;
  if (len1 + len2 <= 7) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        memset(vis, 0, sizeof(vis));
        if (i == j || (!judge(i, len1)) || (!judge(j, len2))) continue;
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
