#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, x, y, i, j;
  cin >> n >> m;
  long long a = 1, b = 1;
  x = 7;
  y = 7;
  while (x < n) {
    a++;
    x *= 7;
  }
  while (y < m) {
    b++;
    y *= 7;
  }
  if (a + b > 7) {
    cout << "0\n";
    return 0;
  }
  long long c1, c2, ans = 0;
  int flag;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      vector<int> vis(7, 0);
      x = i;
      y = j;
      c1 = c2 = 0;
      while (c1 != a) {
        vis[x % 7]++;
        x /= 7;
        c1++;
      }
      while (c2 != b) {
        vis[y % 7]++;
        y /= 7;
        c2++;
      }
      if (*max_element(vis.begin(), vis.end()) <= 1) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
