#include <bits/stdc++.h>
using namespace std;
typedef struct dva {
  int otvet;
  int raz;
} dva;
dva func(int &x) {
  dva p;
  int k = 1, ost = 0, otvet = 0, raz = 1;
  while (x >= 7) {
    int d = x / 7;
    ost = x - d * 7;
    x = x / 7;
    otvet += ost * k;
    raz += 1;
    k *= 10;
  }
  otvet += k * x;
  p.otvet = otvet;
  p.raz = raz;
  return p;
}
int main() {
  int n, m;
  cin >> n >> m;
  int xyz = 0;
  int nsev = 0, msev = 0, nraz = 1, mraz = 1;
  int d = n - 1;
  dva s = func(d);
  nsev = s.otvet;
  nraz = s.raz;
  d = m - 1;
  s = func(d);
  msev = s.otvet;
  mraz = s.raz;
  if (mraz + nraz > 7) {
    cout << 0;
    return 0;
  }
  int masn[n][7];
  int masm[m][7];
  for (int j = 0; j < n; j++) {
    for (int k = 0; k < 7; k++) {
      masn[j][k] = 0;
    }
  }
  for (int j = 0; j < m; j++) {
    for (int k = 0; k < 7; k++) {
      masm[j][k] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int g = i;
    dva s = func(g);
    if (i == 0)
      masn[i][0] = nraz;
    else {
      masn[i][0] += nraz - s.raz;
      int temp = s.otvet;
      while (temp >= 10) {
        masn[i][temp % 10] += 1;
        temp = temp / 10;
      }
      masn[i][temp] += 1;
    }
  }
  for (int i = 0; i < m; i++) {
    int g = i;
    dva s = func(g);
    if (i == 0)
      masm[i][0] = mraz;
    else {
      masm[i][0] += mraz - s.raz;
      int temp = s.otvet;
      while (temp >= 10) {
        masm[i][temp % 10] += 1;
        temp = temp / 10;
      }
      masm[i][temp] += 1;
    }
  }
  int mas[7] = {0, 0, 0, 0, 0, 0, 0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int kol = 0;
      for (int k = 0; k < 7; k++) {
        mas[k] = masn[i][k] + masm[j][k];
        if (mas[k] > 1) {
          kol = 1;
          break;
        }
      }
      if (kol == 0) {
        xyz += 1;
      }
    }
  }
  cout << xyz;
  return 0;
}
