#include <bits/stdc++.h>
using namespace std;
int n, m;
int x, y, ans;
vector<int> a, b;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m, x = n, y = m;
  n--, m--;
  while (n) {
    a.push_back(n % 7);
    n /= 7;
  }
  while (m) {
    b.push_back(m % 7);
    m /= 7;
  }
  if (!a.size()) a.push_back(0);
  if (!b.size()) b.push_back(0);
  if (a.size() + b.size() > 7) {
    cout << 0;
    return 0;
  }
  int cnt1[7], cnt2[7];
  for (int i = 0; i < x; i++) {
    int X;
    X = i;
    memset(cnt1, false, sizeof(cnt1));
    for (int l = 1; l <= a.size(); l++) {
      ++cnt1[X % 7];
      X /= 7;
    }
    for (int j = 0; j < y; j++) {
      X = j;
      memset(cnt2, false, sizeof(cnt2));
      for (int l = 1; l <= b.size(); l++) cnt2[X % 7]++, X /= 7;
      bool flag = true;
      for (int l = 0; l < 7; l++)
        if (cnt1[l] + cnt2[l] > 1) {
          flag = false;
          break;
        }
      ans += flag;
    }
  }
  cout << ans;
}
