#include <bits/stdc++.h>   using namespace std;   int arr[15], cnt[7] = {0}, ans = 0;   int j, hr = 0, mi = 0;   int se[100] = {0};   vector<int> na, ma;   void rec(int pos, int a) {     int i;     if (pos == -1) {       ans++;       return;     }     if (pos == mi - 1) {       for (i = 0; i <= na[pos]; i++) {         if (cnt[i] != 1) {           cnt[i] = 1;           if (i == na[pos]) se[pos] = 1;           rec(pos - 1, i);           cnt[i] = 0;         }         se[pos] = 0;       }     } else if (se[pos + 1] == 0) {       for (i = 0; i < 7; i++) {         if (cnt[i] != 1) {           cnt[i] = 1;           rec(pos - 1, i);           cnt[i] = 0;         }       }     } else {       for (i = 0; i <= na[pos]; i++) {         if (cnt[i] != 1) {           cnt[i] = 1;           if (i == na[pos]) {             se[pos] = 1;           }           rec(pos - 1, i);           cnt[i] = 0;         }         se[pos] = 0;       }     }   }   bool chk(int *a, int n) {     int i, flg = 0;     for (i = 0; i < n - 1; i++) {       if (a[i] <= a[i + 1])         flg = 1;       else {         flg = 0;         break;       }     }     return flg;   }   int main() {     arr[0] = 1;     for (int i = 1; i <= 10; i++) {       arr[i] = arr[i - 1] * 7;     }     int n, m, i;     cin >> n >> m;     n = n - 1;     m = m - 1;     int x = n, y = m;     if (y == 0) {       na.push_back(0);       mi++;     }     while (y != 0) {       na.push_back(y % 7);       mi++;       y = y / 7;     }     if (x == 0) {       na.push_back(0);       hr++;     }     while (x != 0) {       na.push_back(x % 7);       hr++;       x = x / 7;     }     if (hr + mi > 7)       ans = 0;     else {       int pos = na.size() - 1;       for (i = 0; i <= na[pos]; i++) {         cnt[i] = 1;         if (i == na[pos]) se[pos] = 1;         rec(pos - 1, i);         cnt[i] = 0;         se[pos] = 0;       }     }     cout << ans << endl;     return 0;   }   