#include <bits/stdc++.h>
using namespace std;
int64_t ans = 0;
void check(int tempa[], int tempb[], int nd, int md) {
  int count[7] = {0}, temp = 1, j;
  for (j = 0; j < nd; j++) {
    count[tempa[j]] += 1;
  }
  for (j = 0; j < md; j++) {
    count[tempb[j]] += 1;
  }
  for (j = 0; j < 7; j++) {
    if (count[j] > 1) {
      temp = 0;
    }
  }
  ans += temp;
}
int main() {
  int64_t n, m, ndigits = 1, mdigits = 1, temp = 7;
  int i, j;
  cin >> n >> m;
  while (n > temp) {
    temp *= 7;
    ndigits++;
  }
  temp = 7;
  while (m > temp) {
    temp *= 7;
    mdigits++;
  }
  if (ndigits + mdigits > 7) {
    cout << "0\n";
  } else {
    int tempa[8] = {0}, tempb[8] = {0}, index, k;
    for (i = 0; i < n; i++) {
      for (j = 0; j < mdigits; j++) {
        tempb[j] = 0;
      }
      for (j = 0; j < m; j++) {
        check(tempa, tempb, ndigits, mdigits);
        if (j < m - 1) {
          index = mdigits - 1;
          tempb[index] += 1;
          while (tempb[index] == 7) {
            tempb[index - 1] += 1;
            tempb[index] = 0;
            index -= 1;
          }
        }
      }
      if (i < n - 1) {
        index = ndigits - 1;
        tempa[index] += 1;
        while (tempa[index] == 7) {
          tempa[index - 1] += 1;
          tempa[index] = 0;
          index -= 1;
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
