#include <bits/stdc++.h>
using namespace std;
long long int digit_count(long long int a) {
  long long int count = 1;
  for (long long int i = 7; i < a; i *= 7) count++;
  return count;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int digit_n, digit_m;
  digit_n = digit_count(n);
  digit_m = digit_count(m);
  if (digit_n == 0) digit_n = 1;
  if (digit_m == 0) digit_m = 1;
  long long int ans = 0;
  if (digit_m + digit_n > 7)
    cout << 0 << endl;
  else {
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        long long int used[7] = {0};
        long long int base7_i, base7_j;
        long long int tempest = 0;
        for (long long int temp = i; tempest != digit_n; tempest++, temp /= 7) {
          used[temp % 7] += 1;
        }
        tempest = 0;
        for (long long int temp = j; tempest != digit_m; tempest++, temp /= 7) {
          used[temp % 7] += 1;
        }
        if (*max_element(used, used + 7) <= 1) ans++;
      }
    }
    cout << ans;
  }
  return 0;
}

### Prompt

Please formulate a CPP solution to the following problem:

Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches.

First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hours, and each hour in m minutes. Personal watches of each robber are divided in two parts: first of them has the smallest possible number of places that is necessary to display any integer from 0 to n - 1, while the second has the smallest possible number of places that is necessary to display any integer from 0 to m - 1. Finally, if some value of hours or minutes can be displayed using less number of places in base 7 than this watches have, the required number of zeroes is added at the beginning of notation.

Note that to display number 0 section of the watches is required to have at least one place.

Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.

Input

The first line of the input contains two integers, given in the decimal notation, n and m (1 ≤ n, m ≤ 109) — the number of hours in one day and the number of minutes in one hour, respectively.

Output

Print one integer in decimal notation — the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.

Examples

Input

2 3


Output

4


Input

8 2


Output

5

Note

In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).

In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long int digit_count(long long int a) {
  long long int count = 1;
  for (long long int i = 7; i < a; i *= 7) count++;
  return count;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int digit_n, digit_m;
  digit_n = digit_count(n);
  digit_m = digit_count(m);
  if (digit_n == 0) digit_n = 1;
  if (digit_m == 0) digit_m = 1;
  long long int ans = 0;
  if (digit_m + digit_n > 7)
    cout << 0 << endl;
  else {
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        long long int used[7] = {0};
        long long int base7_i, base7_j;
        long long int tempest = 0;
        for (long long int temp = i; tempest != digit_n; tempest++, temp /= 7) {
          used[temp % 7] += 1;
        }
        tempest = 0;
        for (long long int temp = j; tempest != digit_m; tempest++, temp /= 7) {
          used[temp % 7] += 1;
        }
        if (*max_element(used, used + 7) <= 1) ans++;
      }
    }
    cout << ans;
  }
  return 0;
}

```