#include <bits/stdc++.h>
using namespace std;
int N, M;
int used[10];
int main() {
  cin >> N >> M;
  int len1 = 1, len2 = 1;
  for (int a = 7; a < N; a *= 7) {
    ++len1;
  }
  for (int b = 7; b < M; b *= 7) {
    ++len2;
  }
  int answer = 0;
  if (len1 + len2 <= 7) {
    for (int i = 0; i != N; ++i) {
      for (int j = 0; j != M; ++j) {
        for (int k = 0; k <= 6; ++k) {
          used[k] = 0;
        }
        for (int a = i, k = 0; k != len1; ++k, a /= 7) {
          used[a % 7]++;
        }
        for (int b = j, k = 0; k != len2; ++k, b /= 7) {
          used[b % 7]++;
        }
        int mx = 0;
        for (int i = 0; i < 7; ++i) {
          mx = max(mx, used[i]);
        }
        if (mx < 2) {
          ++answer;
        }
      }
    }
  }
  cout << answer << '\n';
  return 0;
}
