#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int len1 = 1, len2 = 1;
  for (int a = 7; a < n; a *= 7) ++len1;
  for (int b = 7; b < m; b *= 7) ++len2;
  int ans = 0;
  if (len1 + len2 <= 7)
    for (int i = 0; i != n; ++i)
      for (int j = 0; j != m; ++j) {
        vector<int> vi(7, 0);
        for (int a = i, k = 0; k != len1; a /= 7, ++k) vi[a % 7] += 1;
        for (int b = j, k = 0; k != len2; b /= 7, ++k) vi[b % 7] += 1;
        if (*max_element(vi.begin(), vi.end()) <= 1) ++ans;
      }
  printf("%d\n", ans);
  return 0;
}
