#include <bits/stdc++.h>
using namespace std;
int n, m;
int b1, b2;
int cnt = 0;
void check(string s) {
  int hour = 0, minute = 0;
  for (int i = s.size() - 1; i >= s.size() - b1; i--) {
    hour *= 7;
    hour += (s[i] - '0');
  }
  for (int i = s.size() - b1 - 1; i >= 0; i--) {
    minute *= 7;
    minute += (s[i] - '0');
  }
  if (hour <= n && minute <= m) {
    cnt++;
  }
}
void f(string s, int idx, int mask) {
  if (idx == b1 + b2) {
    check(s);
  }
  for (int i = 0; i < 7; i++) {
    if ((mask & (1 << i)) == 0) {
      f(s + char('0' + i), idx + 1, (mask | (1 << i)));
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin >> n >> m;
  n--, m--;
  b1 = b2 = 0;
  int x = n;
  if (x == 0) b1 = 1;
  while (x > 0) {
    b1++;
    x /= 7;
  }
  x = m;
  if (x == 0) b2 = 1;
  while (x > 0) {
    b2++;
    x /= 7;
  }
  if (b1 + b2 > 7) return cout << 0 << endl, 0;
  f("", 0, 0);
  cout << cnt << endl;
  return 0;
}
