#include <bits/stdc++.h>
using namespace std;
int digits(int n) {
  if (n == 0) return 1;
  int d = 0;
  while (n != 0) {
    n = n / 7;
    d++;
  }
  return d;
}
void septel(int a[], int num, int x) {
  for (int i = num - 1; i >= 0; i--) {
    a[i] = x % 7;
    x = x / 7;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  n--;
  m--;
  int a, b;
  a = digits(n);
  b = digits(m);
  if (a + b > 7) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      int cnt[7] = {0};
      int x = i;
      int y = j;
      int k = 0;
      int l = 0;
      while (k < a) {
        cnt[x % 7]++;
        x = x / 7;
        k++;
      }
      while (l < b) {
        cnt[y % 7]++;
        y = y / 7;
        l++;
      }
      int ch = 1;
      for (int i = 0; i < 7; i++) {
        if (cnt[i] > 1) {
          ch = 0;
          break;
        }
      }
      ans = ans + ch;
    }
  }
  cout << ans << endl;
}
