#include <bits/stdc++.h>
using namespace std;
int n, m;
int cal(int x) {
  int ans = 0;
  if (x <= 6) return 1;
  while (x) {
    x /= 7;
    ans++;
  }
  return ans;
}
bool is(int x, int a, int y, int b) {
  int xx[10];
  int yy[10];
  int vis[10];
  memset(vis, 0, sizeof(vis));
  memset(xx, 0, sizeof(xx));
  memset(yy, 0, sizeof(yy));
  int i = 0;
  while (x) {
    xx[i++] = x % 7;
    x /= 7;
  }
  i = 0;
  while (y) {
    yy[i++] = y % 7;
    y /= 7;
  }
  for (i = 0; i < a; i++) vis[xx[i]]++;
  for (i = 0; i < b; i++) vis[yy[i]]++;
  for (i = 0; i < 7; i++)
    if (vis[i] > 1) return false;
  return true;
}
int main() {
  int i, j;
  while (~scanf("%d%d", &n, &m)) {
    int a = cal(n - 1);
    int b = cal(m - 1);
    if (a + b > 7) {
      printf("0\n");
      continue;
    }
    int ans = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (is(i, a, j, b)) ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
