#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, i, j, k, l1 = 1, l2 = 1, s, r[7], z = 0;
  cin >> n >> m;
  for (i = 7; i < n; i *= 7) l1++;
  for (i = 7; i < m; i *= 7) l2++;
  if (l1 + l2 < 8)
    for (i = 0; i < n; ++i)
      for (j = 0; j < m; ++j) {
        for (k = 0; k < 7; ++k) r[k] = 0;
        for (s = i, k = 0; k < l1; s /= 7, ++k) r[s % 7]++;
        for (s = j, k = 0; k < l2; s /= 7, ++k) r[s % 7]++;
        for (k = 0; k < 7; k++)
          if (r[k] > 1) break;
        if (k == 7) z++;
      }
  cout << z;
}
