#include <bits/stdc++.h>
using namespace std;
const long long eps = 1e9 + 7;
const double inf = 1e-12;
bool f(int a, int len1, int b, int len2) {
  int arr[7];
  fill(arr, arr + 7, 0);
  vector<int> fir(len1), sec(len2);
  int j = len1 - 1;
  while (a > 0) {
    fir[j] = a % 7;
    a /= 7;
    --j;
  }
  j = len2 - 1;
  while (b > 0) {
    sec[j] = b % 7;
    b /= 7;
    --j;
  }
  for (int i = 0; i < fir.size(); ++i) {
    ++arr[fir[i]];
    if (arr[fir[i]] > 1) {
      return false;
    }
  }
  for (int i = 0; i < sec.size(); ++i) {
    ++arr[sec[i]];
    if (arr[sec[i]] > 1) {
      return false;
    }
  }
  return true;
}
int main() {
  long long n, m;
  cin >> n >> m;
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i < n; i *= 7) {
    ++cnt1;
  }
  for (int i = 1; i < m; i *= 7) {
    ++cnt2;
  }
  if (n == 1) {
    cnt1 = 1;
  }
  if (m == 1) {
    cnt2 = 1;
  }
  long long res = 0;
  if (n * m <= 1e6) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (f(i, cnt1, j, cnt2)) {
          ++res;
        }
      }
    }
  }
  cout << res;
  return 0;
}
