#include <bits/stdc++.h>
using namespace std;
void convert(int num, int arr[], int sz) {
  while (num) {
    arr[sz - 1] = num % 7;
    num /= 7;
    sz--;
  }
}
int check(int arr1[], int sz1, int arr2[], int sz2) {
  int arr[7] = {0};
  for (int i = 0; i < sz1; i++) {
    arr[arr1[i]]++;
    if (arr[arr1[i]] > 1) return 0;
  }
  for (int i = 0; i < sz2; i++) {
    arr[arr2[i]]++;
    if (arr[arr2[i]] > 1) return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  int t, i, j;
  long long hr, minute;
  cin >> hr >> minute;
  hr--;
  minute--;
  long long left_pos = 0;
  long long temp = 1;
  while (temp < hr) {
    temp *= 7;
    left_pos++;
  }
  if (temp == hr) left_pos++;
  long long right_pos = 0;
  temp = 1;
  while (temp < minute) {
    temp *= 7;
    right_pos++;
  }
  if (temp == minute) right_pos++;
  if (left_pos == 0) left_pos++;
  if (right_pos == 0) right_pos++;
  if (left_pos + right_pos > 8) {
    cout << "0";
    return 0;
  }
  int left_arr[left_pos], right_arr[right_pos];
  long long ans = 0;
  for (i = 0; i <= hr; i++) {
    for (j = 0; j <= minute; j++) {
      memset(left_arr, 0, sizeof(left_arr));
      memset(right_arr, 0, sizeof(right_arr));
      convert(i, left_arr, left_pos);
      convert(j, right_arr, right_pos);
      if (check(left_arr, left_pos, right_arr, right_pos)) ans++;
    }
  }
  cout << ans;
}
