#include <bits/stdc++.h>
using namespace std;
int a[8];
int main() {
  int n, m;
  cin >> n >> m;
  int xx = n;
  int kk = m;
  int ans = 0;
  int len1 = 1, len2 = 1;
  for (int b = 7; b < n; b *= 7) len1++;
  for (int b = 7; b < m; b *= 7) len2++;
  if (len2 + len1 > 7) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int z = i, f = 0; f != len1; f++, z /= 7) {
        int x = z % 7;
        a[x]++;
      }
      for (int z = j, f = 0; f != len2; f++, z /= 7) {
        int x = z % 7;
        a[x]++;
      }
      bool ok = false;
      for (int d = 0; d < 8; d++)
        if (a[d] > 1) ok = true;
      if (ok == false) ans++;
      for (int d = 0; d < 8; d++) a[d] = 0;
    }
  }
  cout << ans;
}
