#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int N = 2000010;
int b, fatorial[10];
vector<int> seq;
int total, divisao;
void base_7(int x, bool flag) {
  vector<int> aux;
  while (x) {
    aux.push_back(x % 7);
    x /= 7;
  }
  reverse(aux.begin(), aux.end());
  for (int i = 0; i < aux.size(); i++) seq.push_back(aux[i]);
}
long long pd[9][(1 << 9)][9];
long long solve(int k, int bitmask, int ant) {
  if (k == total) return 1LL;
  long long &res = pd[k][bitmask][ant];
  if (res != -1) return res;
  long long r = 0;
  if (k == 0 or k == divisao) {
    for (int i = 0; i < seq[k]; i++) {
      if ((bitmask & (1 << i)) == 0) {
        r += solve(k + 1, bitmask | (1 << i), 0);
      }
    }
    if ((bitmask & (1 << seq[k])) == 0) {
      r += solve(k + 1, bitmask | (1 << seq[k]), 1);
    }
  } else {
    if (ant == 0) {
      for (int i = 0; i < 7; i++) {
        if ((bitmask & (1 << i)) == 0) {
          r += solve(k + 1, bitmask | (1 << i), 0);
        }
      }
    } else {
      for (int i = 0; i < seq[k]; i++) {
        if ((bitmask & (1 << i)) == 0) {
          r += solve(k + 1, bitmask | (1 << i), 0);
        }
      }
      if ((bitmask & (1 << seq[k])) == 0) {
        r += solve(k + 1, bitmask | (1 << seq[k]), 1);
      }
    }
  }
  return res = r;
}
int main(void) {
  memset(pd, -1, sizeof pd);
  int n, m;
  fatorial[0] = 1;
  for (int i = 1; i < 10; i++) fatorial[i] = i * fatorial[i - 1];
  scanf("%d %d", &n, &m);
  if (n == 1) seq.push_back(0);
  base_7(n - 1, false);
  divisao = seq.size();
  base_7(m - 1, true);
  if (m == 1) seq.push_back(0);
  total = seq.size();
  if (total > 7) {
    printf("0\n");
    return 0;
  }
  cout << solve(0, 0, 0) << endl;
  return 0;
}
