#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m;
  scanf("%lld%lld", &n, &m);
  long long int x, y;
  long long int temp = n - 1;
  x = y = 0;
  long long int mul = 1;
  while (temp != 0) {
    int d = temp % 7;
    x = x + mul * d;
    mul *= 10;
    temp /= 7;
  }
  temp = m - 1;
  mul = 1;
  while (temp != 0) {
    int d = temp % 7;
    y = y + mul * d;
    mul *= 10;
    temp /= 7;
  }
  vector<int> a, b;
  temp = x;
  while (temp != 0) {
    int d = temp % 10;
    a.push_back(d);
    temp /= 10;
  }
  temp = y;
  while (temp != 0) {
    int d = temp % 10;
    b.push_back(d);
    temp /= 10;
  }
  if (y == 0) b.push_back(0);
  if (x == 0) a.push_back(0);
  if (a.size() + b.size() > 7) {
    cout << "0" << endl;
    return 0;
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    temp = i;
    x = y = 0;
    mul = 1;
    while (temp != 0) {
      int d = temp % 7;
      x = x + mul * d;
      mul *= 10;
      temp /= 7;
    }
    vector<int> c1;
    temp = x;
    while (temp != 0) {
      int d = temp % 10;
      c1.push_back(d);
      temp /= 10;
    }
    for (int k = c1.size(); k < a.size(); k++) c1.push_back(0);
    for (int j = 0; j < m; j++) {
      vector<int> c2;
      temp = j;
      mul = 1;
      y = 0;
      while (temp != 0) {
        int d = temp % 7;
        y = y + mul * d;
        mul *= 10;
        temp /= 7;
      }
      temp = y;
      while (temp != 0) {
        int d = temp % 10;
        c2.push_back(d);
        temp /= 10;
      }
      for (int k = c2.size(); k < b.size(); k++) c2.push_back(0);
      int flag = 0;
      for (int k2 = 0; k2 < c1.size(); k2++)
        for (int k3 = 0; k3 < c2.size(); k3++)
          if (c1[k2] == c2[k3]) {
            flag = 1;
            break;
          }
      for (int k2 = 0; k2 < c1.size(); k2++)
        for (int k3 = k2 + 1; k3 < c1.size(); k3++)
          if (c1[k2] == c1[k3]) {
            flag = 1;
            break;
          }
      for (int k2 = 0; k2 < c2.size(); k2++)
        for (int k3 = k2 + 1; k3 < c2.size(); k3++)
          if (c2[k2] == c2[k3]) {
            flag = 1;
            break;
          }
      if (flag == 0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
