#include <bits/stdc++.h>
using namespace std;
int memo[823543][7];
int main(void) {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  int t = n - 1;
  int digitn = 0;
  while (t) {
    t /= 7;
    digitn++;
  }
  t = m - 1;
  int digitm = 0;
  while (t) {
    t /= 7;
    digitm++;
  }
  digitm = max(1, digitm);
  digitn = max(1, digitn);
  if (digitn + digitm > 7) {
    printf("0");
    return 0;
  }
  int tot = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int arr[10];
      memset(arr, 0, sizeof(arr));
      t = i;
      int kali = digitn;
      while (kali) {
        arr[t % 7]++;
        t /= 7;
        kali--;
      }
      t = j;
      kali = digitm;
      while (kali) {
        arr[t % 7]++;
        t /= 7;
        kali--;
      }
      bool valid = true;
      for (int k = 0; k < 7; k++)
        if (arr[k] > 1) valid = false;
      if (valid) tot++;
    }
  }
  cout << tot;
  return 0;
}
