#include <bits/stdc++.h>
using namespace std;
const int DEBUG = 0;
namespace defs {
template <class Type>
Type read() {
  Type aa;
  int bb = 1, ch;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  ch == '-' ? aa = 0, bb = -1 : aa = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') aa = aa * 10 + ch - '0';
  return bb == 1 ? aa : -aa;
}
const unsigned int rand_x = 11309;
const unsigned int rand_y = 1000000019;
unsigned int rand_cur;
unsigned int rand_int() { return rand_cur = rand_cur * rand_x + rand_y; }
const int inf = 1071026353;
const int mod = 1000000007;
const int modx = 998244353;
}  // namespace defs
namespace lightningwork {
int (*read)() = defs::read<int>;
int n, m, d1, d2;
int vis[10];
int ans;
int get(int x) {
  int ret = 0;
  while (x) {
    x /= 7;
    ++ret;
  }
  (ret < (1) ? ret = 1 : 0);
  return ret;
}
void dfs2(int i, int num) {
  if (i == 0) {
    if (num <= m) {
      ++ans;
    }
  } else {
    for (int j = 0; j < 7; ++j) {
      if (vis[j] == 0) {
        vis[j] = 1;
        dfs2(i - 1, num * 7 + j);
        vis[j] = 0;
      }
    }
  }
}
void dfs(int i, int num) {
  if (i == 0) {
    if (num <= n) {
      dfs2(d2, 0);
    }
  } else {
    for (int j = 0; j < 7; ++j) {
      if (vis[j] == 0) {
        vis[j] = 1;
        dfs(i - 1, num * 7 + j);
        vis[j] = 0;
      }
    }
  }
}
void work() {
  n = read() - 1;
  m = read() - 1;
  d1 = get(n);
  d2 = get(m);
  dfs(d1, 0);
  printf("%d\n", ans);
}
}  // namespace lightningwork
int main() {
  if (0)
    freopen(
        "work"
        ".in",
        "r", stdin),
        freopen(
            "work"
            ".out",
            "w", stdout);
  lightningwork::work();
  if (0) fclose(stdin), fclose(stdout);
  return 0;
}
