//amazing takes time, legendary requires patience
#include "bits/stdc++.h"
#define sd(n) scanf("%d", &(n))
#define rep(i, x, n) for (int i = x, _n = (n); i < _n; ++i)
#define repi(i, a) for(typeof((a).begin()) i = (a).begin(), _##i = (a).end(); i != _##i; ++i)
#define pra(v) repi(it, v) cout << *it << " "; cout << endl;
#define SZ(c) (int)(c).size()
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define VI vector<int>
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define pb push_back
#define mii map<int, int>
#define pii pair<int, int>
#define pip pair<int, pii>
#define F first
#define S second
#define mp make_pair
#define lli long long int
#define llu unsigned long long
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define INF 0x3f3f3f3f
#define pi 3.141592653589793
#define debug 0
using namespace std;
const int MOD = 1e9+7;
const int MAX = 100010;
const double eps = 1e-8;
lli n, m;
int main()
{
cin >> n >> m;
double tmp = 0.0;
if(n > 1)
tmp = log(n-1)/log(7);
lli nd = 1LL + int(tmp);
if(m > 1)
tmp = log(m-1)/log(7);
else
tmp = 0.0;
lli md = 1 + int(tmp);
// cout << nd << " " << md << endl;
if(nd + md > 7)
{
cout << 0 << endl;
return 0;
}
lli cnt = 0;
rep(i, 0, (1<<7))
{
VI v;
rep(j, 0, 7)
{
if((1<<j)&i)
v.pb(j);
}
if(SZ(v) != nd+md) continue;
do
{
lli hr = 0, mi = 0;
rep(i, 0, nd)
hr = hr*7LL + v[i];
rep(i, nd, SZ(v))
mi = mi*7LL + v[i];
if(mi < m and hr < n)
{
// cout << hr << ":" << mi << endl;
cnt++;
}
}while(next_permutation(all(v)));
}
cout << cnt << endl;
return 0;
}
Ly9hbWF6aW5nIHRha2VzIHRpbWUsIGxlZ2VuZGFyeSByZXF1aXJlcyBwYXRpZW5jZQojaW5jbHVkZSAiYml0cy9zdGRjKysuaCIKI2RlZmluZSBzZChuKSBzY2FuZigiJWQiLCAmKG4pKQojZGVmaW5l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