#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void print(long long x) {
  static int a[24];
  int n = 0;
  while (x > 0) {
    a[n++] = x % 10;
    x /= 10;
  }
  if (n == 0) a[n++] = 0;
  while (n--) putchar('0' + a[n]);
  putchar('\n');
}
void from(const char *s) { freopen(s, "r", stdin); }
void to(const char *s) { freopen(s, "w", stdout); }
const int N = 1010;
int a[N], b[N], a_c, b_c, ans, n_c;
bool ck(int b_c) {
  for (int i = 1; i <= b_c; i++)
    for (int j = 1; j <= i - 1; j++)
      if (b[i] == b[j]) return true;
  return false;
}
void dfs(int dep, bool eq) {
  if (ck(dep - 1)) return;
  if (dep == a_c + 1) {
    ans++;
    return;
  }
  if (eq) {
    for (int i = 0; i <= a[dep] - 1; i++) {
      b[dep] = i;
      dfs(dep + 1, 0);
    }
    b[dep] = a[dep];
    dfs(dep + 1, 1);
  } else {
    for (int i = 0; i <= 6; i++) {
      b[dep] = i;
      dfs(dep + 1, eq);
    }
  }
}
void DFS(int dep, bool eq) {
  if (ck(dep - 1)) return;
  if (dep == n_c + 1) {
    dfs(dep, 1);
    return;
  }
  if (eq) {
    for (int i = 0; i <= a[dep] - 1; i++) {
      b[dep] = i;
      DFS(dep + 1, 0);
    }
    b[dep] = a[dep];
    DFS(dep + 1, 1);
  } else {
    for (int i = 0; i <= 6; i++) {
      b[dep] = i;
      DFS(dep + 1, eq);
    }
  }
}
int main() {
  int n = read(), m = read();
  n--, m--;
  if (n == 0) a[++a_c] = 0;
  while (n) {
    a[++a_c] = n % 7;
    n /= 7;
  }
  reverse(a + 1, a + 1 + a_c);
  n_c = a_c;
  if (m == 0) a[++a_c] = 0;
  while (m) {
    a[++a_c] = m % 7;
    m /= 7;
  }
  reverse(a + 1 + n_c, a + 1 + a_c);
  DFS(1, 1);
  printf("%d\n", ans);
  return 0;
}
