#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, hours_digit = 1, minutes_digit = 1;
  cin >> n >> m;
  long long int temp = 0;
  for (long long int a = 7; a < n; a *= 7) hours_digit += 1;
  for (long long int b = 7; b < m; b *= 7) minutes_digit += 1;
  if (hours_digit + minutes_digit > 7) {
    cout << 0 << endl;
    return 0;
  }
  long long int final_ans = 0;
  for (int i = 0; i < n; i++) {
    vector<int> arr(7, 0);
    temp = i;
    int temp2 = 0;
    while (temp > 0) {
      arr[temp % 7]++;
      temp = temp / 7;
      temp2++;
    }
    arr[0] += hours_digit - temp2;
    for (int j = 0; j < m; j++) {
      vector<int> arr2(7, 0);
      temp = j;
      temp2 = 0;
      while (temp > 0) {
        arr2[temp % 7]++;
        temp = temp / 7;
        temp2++;
      }
      arr2[0] += minutes_digit - temp2;
      int flag = 0;
      for (int k = 0; k < 7; k++) {
        if (arr2[k] + arr[k] > 1) {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        final_ans++;
      }
    }
  }
  cout << final_ans << endl;
}
