#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define ll long long
vector<string> hours, minuts;
string solve(ll a)
{
	string h = "";
	if (a == 0)
	{
		h = "0";
		return h;
	}
	while (a)
	{
		h += ((a % 7)+48);
		a /= 7;
	}
	string d = "";
	for (int i = h.length()-1; i >= 0; i--)
	{
		d += h[i];
	}
	return d;
}
bool comp(string t)
{
	map<char,int>k;
	for (int i = 0; i < t.length(); i++)
	{
		k[t[i]]++;
		if (k[t[i]]>1)return 0;
	}
	return 1;
}
bool cm(string e, string w)
{
	map<char, int>k;
	for (int i = 0; i < e.length(); i++)
	{
		k[e[i]]++;
		if (k[e[i]]>1)return 0;
	}
	for (int i = 0; i < w.length(); i++)
	{
		k[w[i]]++;
		if (k[w[i]]>1)return 0;
	}
	return 1;
}
int main()
{
	ll n, m;
	cin >> n >> m;
	string nn = solve(n-1);
	string mm = solve(m-1);
	//cout << nn <<"   "<< mm;
	//system("pause");
	if (nn.length() + mm.length() > 8)
	{
		cout << 0;
		return 0;
	}
	int x = nn.length(), y = mm.length();
	for (int i = 0; i < min(n,m); i++)
	{
		string h=solve(i);
		bool cc = comp(h);
		//cout << h << endl;
		if (!cc)continue;
		int q = h.length();

		if (q == x-1)
		{
				string l = '0' + h;;
			//cout << h << endl;
			hours.push_back(l);

		}
		else if (q == x)
		{
			//cout << h << endl;
				hours.push_back(h);

		}
		if (q == y - 1)
		{
			h = '0' + h;
				//cout << h << endl;
				minuts.push_back(h);
		}
		else if (q == y)
		{
			//cout << h << endl;
				minuts.push_back(h);
		}

	}
	if (n > m)
	{
		for (int i = min(n, m); i < max(n, m); i++)
		{
			string h = solve(i);
			//cout << h << endl;
			bool cc = comp(h);
			if (!cc)continue;
			int q = h.length();
			if (q == x - 1)
			{
				h = '0' + h;
				hours.push_back(h);

			}
			else if (q == x)
			{

				hours.push_back(h);

			}
		}
	}
	else if (m > n){
		for (int i = min(n, m); i < max(n, m); i++)
		{
			string h = solve(i);
			bool c = comp(h);
			if (!c)continue;
			int q = h.length();
			if (q == y - 1)
			{
				h = '0' + h;
				//cout << h << endl;
				minuts.push_back(h);
			}
			else if (q == y)
			{
				minuts.push_back(h);
			}
		}
	}
	//cout << hours.size();
	//system("pause");
	ll ttt = 0;
	for (vector<string>::iterator i = hours.begin(); i != hours.end(); i++)
	{
		for (vector<string>::iterator j = minuts.begin(); j != minuts.end(); j++)
		{
			//cout << *i << "  " << *j << endl;
			if (cm(*i, *j))
			{
				ttt++;
				//cout << *i << "  " << *j << endl;

			}
		}
	}
	cout << ttt;
	//system("pause");
	//16808 7
}

#include<iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, m, cnt1 = 1, cnt2 = 1, ans;
long double nn, mm ;
int main()
{
    cin >> n >> m;
    nn = n, mm = m;
    if(n > 1)
        cnt1 = log(nn - 1) / log(7.0) + 1;
    if(m > 1)
        cnt2 = log(mm - 1) / log(7.0) + 1 ;
    if(cnt1 + cnt2 > 7)
        return cout << 0, 0;
    for(ll i = 0; i < n * m; i++)
    {
        int yes = 1;
        ll a = i / m, b = i % m;
        int arr[9] = {0};
        for(int j = 0; j < cnt1; j++)
            arr[a % 7]++, a /= 7;
        for(int j = 0; j < cnt2; j++)
            arr[b % 7]++, b /= 7;
        for(int i = 0; i < 7; i++)
            if(arr[i] > 1)
                yes = 0;
        ans += yes;
    }
    cout << ans;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define si(x) scanf("%d",&x)
#define sc(ch) scanf(" %c",&ch);
#define sl(x) scanf("%I64d",&x)
#define pi(x) printf("%d ",x)
#define nl printf("\n")
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define pii pair<int,int>
#define RESET(a) memset(a,-1,sizeof(a))
#define CLEAR(a) memset(a,0,sizeof(a))
#define all(v)   v.begin(),v.end()
#define trv(it,v) for(it=v.begin();it!=v.end();it++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define MIN INT_MIN
#define MAX INT_MAX
//freopen("op-1.txt","w",stdout);
int x,y;
int N;
int n,m;
int ct=0;
int get(int n)
{
    if(n==0)
        return 0;
    return 1 + get(n/7);
}

void check(vector<int> &v)
{
   // if(v.empty())
     //   return ;
    vector<int> b(10,0);
    for(auto it : v)
    {
        if(b[it]==1)
            return ;
        else
            b[it]=1;
    }
    ll x1=0;
    ll p = 1;
    for(int i=x-1; i>=0; i--){
        x1 += p*v[i];
        p = 7*p;
    }

    ll x2=0;
    p=1;
    for(int i=v.size()-1; i>=x; i--){
        x2 += p*v[i];
        p = 7*p;
    }

//    pi(x1),pi(n), pi(x2),pi(m);
//    nl;
    if(x1>=0 && x1<n && x2>=0 && x2<m){
    //    pi(x);
//        for(auto it : v)
//            pi(it);
////      //  pi(x1), pi(x2)
//    nl;
        ct++;
    }
    return ;
}

void recur(int i, vector<int> &v)
{
    if(i==N){
        check(v);
        return ;
    }
    for(int j=0; j<=6; j++){
        v.pb(j);
        recur(i+1, v);
        v.pop_back();
    }
}

int main()
{

    cin >> n >> m;
    if(n-1 == 0)
        x = 1;
    else
        x = get(n-1);
    if(m-1 == 0)
        y=1;
    else
        y = get(m-1);

//    pi(x), pi(y);
//    nl;
//    nl;

    vector<int> v;
    if(x+y >7){
        cout << "0";
        return 0;
    }
    N = x+y;
    recur(0,v);
    cout << ct;
    return 0;
}

/*
 * Author       : YangDavid
 * Created Time : 2020年02月22日 星期六 20时28分00秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int n, m, b1 = 1, b2 = 1, p1 = 7, p2 = 7, a[10], vis[10], cnt;
void dfs(int dep) {
    if(dep == b1 + b2) {
        int hr = 0, mn = 0;
        for(int i = 0; i < b1; ++i) hr = hr * 7 + a[i];
        for(int i = b1; i < b1 + b2; ++i) mn = mn * 7 + a[i];
        cnt += hr < n && mn < m;
        return ;
    }
    for(int i = 0; i < 7; ++i) if(!vis[i]) {
        vis[i] = true; a[dep] = i;
        dfs(dep + 1);
        vis[i] = false;
    }
}
int main() {
    scanf("%d%d", &n, &m);
    while(p1 < n) b1++, p1 *= 7;
    while(p2 < m) b2++, p2 *= 7;
    if(b1 + b2 > 7) { puts("0"); return 0; }
    dfs(0);
    printf("%d\n", cnt);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
	int i, n, m, sn = 0, sm = 0, dign = 0, digm = 0, ten, lim, totdig, tempo, ans = 0;
	cin>>n>>m;
	n--, m--;
	ten = 1, tempo = n;
	while (tempo>0) {
	    sn += (ten * (tempo%7));
	    ten *= 10;
	    tempo/=7;
	    dign++;
	}
	ten = 1, tempo = m;
	while (tempo>0) {
	    sm += (ten * (tempo%7));
	    ten *= 10;
	    tempo/=7;
	    digm++;
	}
	if (dign == 0) dign++;
	if (digm == 0) digm++;
	totdig = dign + digm;
	if (totdig > 7) {
	    cout<<0<<endl;
	    return 0;
	}
	lim = pow(7, totdig);
	for (i=0; i<lim; i++) {
	    int x = 0, y = 0, temp = i, digix = 0, xdigix = 0, ydigix = 0, ten = 1;
	    int mark[7] = {0};
	    while (temp > 0) {
	        tempo = temp%7;
	        if (mark[tempo] == 0) {
	            digix++;
	            mark[tempo] = 1;
	            if (xdigix < digm) {
	                x += (ten * tempo);
	                xdigix++;
	                if (xdigix == digm) ten = 1;
	                else ten *= 10;
	            } else if (ydigix < dign) {
	                y += (ten * tempo);
	                ydigix++;
	                ten *= 10;
	            } else break;
	        } else break;
	        temp /= 7;
	    }
	    if (digix < totdig && mark[0] == 0) digix++;
	    if (temp == 0 && digix == totdig && x <= sm && y <= sn) {
	       // cout<<x<<" "<<y<<endl;
	        ans++;
	    }
	}
	cout<<ans<<endl;
	return 0;
}

#include<bits/stdc++.h>
#define lc(a) (a<<1)
#define rc(a) (a<<1|1)
#define MID(a,b) ((a+b)>>1)
#define fin(name)  freopen(name,"r",stdin)
#define fout(name) freopen(name,"w",stdout)
#define clr(arr,val) memset(arr,val,sizeof(arr))
#define _for(i,start,end) for(int i=start;i<=end;i++)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long LL;
const int N=105;
const int INF=0x3f3f3f3f;
const double eps=1e-10;

int used[7];

int main(){
	FAST_IO;
	int n,m;
	cin>>n>>m;

	int len1=0,len2=0;
	//注意要-1
	for(int i=n-1;i!=0;i/=7)
		len1++;
	if(len1==0) len1++;
	for(int i=m-1;i!=0;i/=7)
		len2++;
	if(len2==0) len2++;
	LL ans=0;
	if(len1+len2<=7){
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				memset(used,0,sizeof(used));
				bool flag=true;
				for(int k=1,tmp=i;k<=len1;k++){
					used[tmp%7]++;
					tmp/=7;
				}
				for(int k=1,tmp=j;k<=len2;k++){
					used[tmp%7]++;
					tmp/=7;
				}

				for(int k=0;k<7;k++){
					if(used[k]>1)
						flag=false;
				}
				ans+=flag;
			}
		}
	}

	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(long long i=a;i<=b;i++)

ll n,m,a[]={0,1,2,3,4,5,6},c,d,f;
map<pair<ll,ll>,bool>b;

ll br(ll x){
	ll y=7,g=1;
	while(y<=x){
		y*=7;
		g++;
	}
	return g;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>m;
	if(br(n-1)+br(m-1)>7)cout<<0;
	else{
		do{
			c=0;
			d=0;
			f(i,0,br(n-1)-1){
				c+=a[i];
				if(i<br(n-1)-1)c*=7;
			}
			f(i,br(n-1),br(n-1)+br(m-1)-1){
				d+=a[i];
				if(i<br(n-1)+br(m-1)-1)d*=7;
			}
			if(c<n&&d<m&&!b[make_pair(c,d)]){
				f++;
				b[make_pair(c,d)]=true;
			}
		}while(next_permutation(a,a+7));
		cout<<f;
	}
}

#include <bits/stdc++.h>
using namespace std;
int nums[25];
int ed, g[256], f[256], d[256], dp[12][256];
int dfs(int i, int u, int s) {
	if (i == -1) return ed == s;
	if (!u && dp[i][s] != -1) return dp[i][s];
	int maxv = u ? nums[i] : 6, ret = 0;
	for (int j = 0; j <= maxv; ++j)
		if ((s & (1 << j)) == 0)
			ret += dfs(i - 1, u && (j == maxv), s | (1 << j));
	return u ? ret : dp[i][s] = ret;
}
void solve(int n) {
	--n;
	int len = 0;
	if (!n) len = 1,nums[0] = 0;
	while (n) {
		nums[len++] = n % 7;
		n /= 7;
	}

	for (int i = 0; i < 256; ++i) {
		memset(dp, 255, sizeof dp);
		ed = i;
		f[i] = dfs(len - 1, 1, 0);
	}
}
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	solve(n);
	memcpy(g, f, sizeof f);
	solve(m);
	long long ans = 0;
	for (int i = 0; i < 256; ++i)
		for (int j = i; j; j = (j - 1) & i)
			d[i] += f[j];

	for (int i = 0; i < 256; ++i)
		ans += 1LL * g[i] * d[255 ^ i];
	cout << ans << endl;
}

/*
ID: nalinpm
PROG: r359p3
LANG: C++
*/
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

void printBaseSeven(unsigned long long int n, int sizeN)
{
    unsigned long long int x = n;
    string str;

    while(sizeN > 0)
    {
        sizeN--;
        int mod = x%7;
        x = x/7;

        switch(mod)
        {
            case 0:
                str += '0';
                break;

            case 1:
                str += '1';
                break;

            case 2:
                str += '2';
                break;

            case 3:
                str += '3';
                break;

            case 4:
                str += '4';
                break;

            case 5:
                str += '5';
                break;

            case 6:
                str += '6';
                break;
        }

    }

    reverse(str.begin(), str.end());
    cout << str ;
    return;
}
int toBaseSeven(unsigned long long int n, string* str)
{
    unsigned long long int x = n;
    int flag = 0;

    (*str).erase((*str).begin() , (*str).end());

    while(x > 0)
    {
        flag++;
        int mod = x%7;
        x = x/7;

        switch(mod)
        {
            case 0:
                (*str) += '0';
                break;

            case 1:
                (*str) += '1';
                break;

            case 2:
                (*str) += '2';
                break;

            case 3:
                (*str) += '3';
                break;

            case 4:
                (*str) += '4';
                break;

            case 5:
                (*str) += '5';
                break;

            case 6:
                (*str) += '6';
                break;
        }

        if(flag > 6)
            break;
    }

    return flag;
}

int checkDistinct(unsigned long long int n, unsigned long long int m , int sizeN, int sizeM) // ouput 1 if distinct; 0 if not
{
    int arr[] = {0,0,0,0,0,0,0};
    int flag = 1;

    unsigned long long int x = n;

    while(sizeN > 0 )
    {
        sizeN--;
        int mod = x % 7;
        x = x / 7;
        switch(mod)
        {
            case 0:
                arr[0]++;
                if(arr[0] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 1:
                arr[1]++;
                if(arr[1] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 2:
                arr[2]++;
                if(arr[2] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 3:
                arr[3]++;
                if(arr[3] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 4:
                arr[4]++;
                if(arr[4] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 5:
                arr[5]++;
                if(arr[5] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 6:
                arr[6]++;
                if(arr[6] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;
        }

    }

    x = m;

    while(sizeM > 0 )
    {
        sizeM--;
        int mod = x % 7;
        x = x / 7;
        switch(mod)
        {
            case 0:
                arr[0]++;
                if(arr[0] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 1:
                arr[1]++;
                if(arr[1] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 2:
                arr[2]++;
                if(arr[2] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 3:
                arr[3]++;
                if(arr[3] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 4:
                arr[4]++;
                if(arr[4] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 5:
                arr[5]++;
                if(arr[5] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;

            case 6:
                arr[6]++;
                if(arr[6] > 1)
                {
                    flag = 0;
                    return 0;
                }
                break;
        }

    }

    if(flag == 1)
        return 1;
    else
        return 0;
}

int main() {

    unsigned long long int n;
    cin >> n;

    unsigned long long int m;
    cin >> m;

    string strn;
    string strm;

    int sizeN = toBaseSeven( (n - 1), &strn );
    int sizeM = toBaseSeven( ( m - 1 ), &strm );
    if(sizeN == 0)
        sizeN++;
    if(sizeM == 0)
        sizeM++;
    int sizeMax = sizeM + sizeN;

    if(sizeN == 0)
        sizeN++;
    if(sizeM == 0)
        sizeM++;
    //reverse(strn.begin(), strn.end() );
    //reverse(strm.begin(), strm.end() );

    //cout << "\nMax Size = " << sizeMax << "\n";
    //cout << "\nsizeN = " << sizeN << "\n";
    //cout << "\nsizeM = " << sizeM << "\n";
    //cout << "\nn base 7 = " << strn << "\n";
    //cout << "\nm base 7 = " << strm << "\n";

    if(sizeMax > 7)
    {
        cout << 0;
        return 0;
    }
    else if(sizeMax == 0)
    {
        cout << 0;
        return 0;
    }

    int ans = 0;

    for(unsigned long long int i = 0; i < n; i++)
    {
        for(unsigned long long int j = 0; j < m; j++)
        {
            if(checkDistinct(i,j, sizeN, sizeM) == 1)
            {
                ans++;
                //cout <<"\nans = " << ans;
                //cout << " " << i << " ";
                //printBaseSeven(i,sizeN);
                //cout << " : " << j << " ";
                //printBaseSeven(j,sizeM);
                //cout << "\n";
            }

        }
    }

    cout << ans << "\n";
    return 0;
}

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e5 + 5;

int n,m;
vector<int> v;
set<string> possible;

int get_len(int x) {
  int len = 1;
  int covered = 7;
  while (covered < x) {
    covered = covered * 7;
    len++;
  }
  return len;
}

int base7(int l, int r) {
  int res = 0;
  int base = 1;
  for (int j=r; j>=l; j--) {
    res += base*v[j];
    base = base * 7;
  }
  return res;
}

string to_time(int x, int y) {
  return std::to_string(x) + ":" + std::to_string(y);
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n>>m;
  for (int i=0; i<7; i++) {
    v.push_back(i);
  }

  int hr_len = get_len(n);
  int mn_len = get_len(m);
  // watch(hr_len); watch(mn_len);

  do {
    for (int i=0; i<6; i++) {
      for (int j=i; j<7; j++) {
        for (int k=j; k<7; k++) {
          //i..j is hours, j+1...k is minutes
          if (j-i+1 != hr_len || k-j != mn_len) continue;
          int hr = base7(i,j);
          int mn = base7(j+1,k);
          if (hr>=n || mn>=m) continue;
          string cur = to_time(hr,mn);
          possible.insert(cur);
        }
      }
    }
  } while (std::next_permutation(v.begin(), v.end()));

  // for (auto p: possible) watch(p);

  out(possible.size());
  return 0;
}

#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>

/*
ID: amerhag1
PROG: pprime
LANG: C++
*/

#define P(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int gcd ( int a , int b )
{
    return ( b==0 ? a : gcd ( b , a%b ) );
}
ll lcm ( int a , int b )
{
    return 1ll*a*b/gcd( a , b );
}

ll po ( ll a , ll b )
{
    if ( b==1 ) { return a; }
    if ( b==0 ) { return 1; }
    ll x = po( a , b/2 );
    if ( b%2 ) { return (x*x*x)%mod; }
    else { return (x*x)%mod; }
}

int nn,mm,l1=0,l2=0,n,m;
vector <int>a,b;
int conv( int x )
{
     int rem,bit=0,base=1;
    while (x>0)
    {
        rem = x%7;
        bit+= rem*base;
        x/=7;
        base*=10;
    }

    return bit;

}

int len( int x )
{
    int l=0;
     while ( x>0 )
    {
        x /= 10;
        l++;
    }
    return l;

}
bool vis[9];

bool check ( int x , int y )
{
    //if ( x==y ) { return 0; }
    if ( len( x )==l1-1 || x==0 ) { vis[0]=1; }
    if ( len( y )==l2-1 || y==0 ) { if ( !vis[0] ) { vis[0]=1; } else { return 0; } }

    while ( x>0 )
    {
        int rem = x%10;
        if ( !vis[rem] ) { vis[rem]=1; } else { return 0; }
        x /= 10;
    }
    while ( y>0 )
    {
        int rem = y%10;
        if ( !vis[rem] ) { vis[rem]=1; } else { return 0; }
        y /= 10;
    }

    return 1;

}

int main()
{
    int n,m;
    cin>>n>>m;
    n--,m--;
    nn=n,mm=m;

    while ( nn>0 )
    {
        nn /= 7;
        l1++;
    }
    while ( mm>0 )
    {
        mm /= 7;
        l2++;
    }

    if ( l1+l2>7 ) { cout<<0; return 0; }

    for ( int i=0 ; i<=n ; i++ )
    {
        int c = conv( i );
        //cout<<c<<endl;
        if ( len(c)<(l1-1) ) { continue; }
        else { a.push_back( c ); }
    }

    for ( int i=0 ; i<=m ; i++ )
    {
        int c = conv( i );
        if ( len(c)<(l2-1) ) { continue; }
        else { b.push_back( c ); }
    }

    ll ans=0;
    //cout<<conv(n)<<" "<<conv(m)<<endl;

    //for ( int i=0 ; i<a.size() ; i++ ) { cout<<a[i]<<" "; }cout<<endl;
    //for ( int i=0 ; i<b.size() ; i++ ) { cout<<b[i]<<" "; }

    for ( int i=0 ; i<a.size() ; i++ )
    {
        for ( int j=0 ; j<b.size() ; j++ )
        {
            memset ( vis , 0 , sizeof( vis ) );
            if ( check( a[i] , b[j] ) ) { ans++; }
        }

    }

    cout<<ans;

    return 0;
}

#include <bits/stdc++.h>
#define N 10
using namespace std;
int ans;
int cnt1,cnt2;
int vis[N];
int n,m;

int getNum(int x){
    int cnt=0;
    while(x>0){
        x/=7;
        cnt++;
    }
    return cnt;
}
void dfs(int d,int sum){
    if(d>cnt1+cnt2)
        return;
    if(d<=cnt1&&sum>=n)
        return;
    if(d>cnt1&&sum>=m)
        return;
    if(d==cnt1+cnt2){
        ans++;
        return;
    }
    for(int i=0;i<7;i++){
        if(!vis[i]){
            vis[i]=1;
            if(d==cnt1)
                dfs(d+1,i);
            else
                dfs(d+1,sum*7+i);
            vis[i]=0;
        }
    }
}
int main(){
    scanf("%d%d",&n,&m);
    cnt1=getNum(n-1),cnt2=getNum(m-1);
    if(n==1)
        cnt1=1;
    if(m==1)
        cnt2=1;
    //cout<<cnt1<<' '<<cnt2<<endl;
    if(cnt1+cnt2>7)
        printf("0\n");
    else{
        dfs(0,0);
        printf("%d\n",ans);
    }
    return 0;
}

#include <bits/stdc++.h>
#define For(i, a, b, c) for(int i = (a); i <= (b); i += (c))
#define Rof(i, a, b, c) for(int i = (a); i >= (b); i += (c))
#define Forn(i, n) For(i, 0, (n) - 1, +1)
#define For1(i, n) For(i, 1, (n), +1)
#define Forall(i, x) for(auto i = (x).begin(); i != (x).end(); i++)
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);

#define fst first
#define snd second
#define pb push_back
#define lower lower_bound
#define upper upper_bound
#define ENDL '\n'
using namespace std;

typedef long long lli;
typedef unsigned long long ulli;
typedef pair<int, int> ii;

template <class T>
struct rge{ T b, e; };

template <class T>
rge<T> range(T i, T j){
  return rge<T>{i, j};
};

template <class A, class B>
ostream & operator << (ostream &os, pair<A, B> p){
  return os << "(" << p.fst << ", " << p.snd << ")";
}

template <class T>
ostream & operator << (ostream &os, rge<T> d){
  os << "[";
  for(auto it = d.b; it != d.e; it++)
    os << (it == d.b ? "": ", ") << *it;
  return os << "]";
}

#define deb(x) cout << #x": " << (x) << '\n';

string base7(lli x){
  if( x == 0 ){
    return "0";
  }
  string r = "";
  while( x > 0 ){
    r.pb(char('0' + x % 7));
    x /= 7;
  }
  reverse(all(r));
  return r;
}

lli inv7(string s){
  lli r = 0;
  Forn(i, sz(s)){
    r *= 7;
    r += s[i] - '0';
  }
  return r;
}

lli ans;

void recur(string &hour, string &minu, lli pos, string &res, set<lli> &ss)
{
  if(pos == sz(hour) + sz(minu))
  {
    string h = res.substr(0, sz(hour));
    string m = res.substr(sz(h), sz(minu));
    if(inv7(h) <= inv7(hour) and inv7(m) <= inv7(minu))
    {
      ans++;
      // deb(res);
      // deb(range(all(ss)));
      // puts("");
    }
    return;
  }
  Forn(i, 7)
  {
    if(!ss.count(i))
    {
      ss.insert(i);
      res.pb(char(i + '0'));
      recur(hour, minu, pos+1, res, ss);
      res.pop_back();
      ss.erase(i);
    }
  }
}

lli n, m;

int main(){ _
  while( cin >> n >> m ){
    n--, m--;
    string hour = base7(n), minu = base7(m);
    // deb(hour);
    // deb(minu);
    if( sz(hour) + sz(minu) > 7 ){
      cout << 0 << ENDL;
    }else{
      ans = 0;
      string bla = "";
      set<lli> ss;
      recur(hour, minu, 0, bla, ss);
      cout << ans << '\n';
    }
  }
  return 0;
}

//BISMILLAHIRRAHMANIRRAHIM
/*
 manus tar shopner soman boro
 all my suceesses are dedicated to my parents
 The true test of a man's character is what he does when no one is watching.
 Don't let your dreams be dreams.

 Author :: Shakil Ahmed
.............AUST_CSE27.........
 prob   ::
 Type   ::
 verdict::

*/

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

// Macro
#define eps 1e-9
#define pi acos(-1.0)
#define ff first
#define ss second
#define re return
#define QI queue<int>
#define SI stack<int>
#define SZ(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sq(a) ((a)*(a))
#define distance(a,b) (sq(a.x-b.x) + sq(a.y-b.y))
#define iseq(a,b) (fabs(a-b)<eps)
#define eq(a,b) iseq(a,b)
#define ms(a,b) memset((a),(b),sizeof(a))
#define G() getchar()
#define MAX3(a,b,c) max(a,max(b,c))
#define II ( { int a ; read(a) ; a; } )
#define LL ( { Long a ; read(a) ; a; } )
#define DD ({double a; scanf("%lf", &a); a;})

double const EPS=3e-8;
using namespace std;

#define FI freopen ("input.txt", "r", stdin)
#define FO freopen ("output.txt", "w", stdout)

typedef long long Long;
typedef long long int64;
typedef unsigned long long ull;
typedef vector<int> vi ;
typedef set<int> si;
typedef vector<Long>vl;
typedef pair<int,int>pii;
typedef pair<string,int>psi;
typedef pair<Long,Long>pll;
typedef pair<double,double>pdd;
typedef vector<pii> vpii;

// For loop

#define forab(i, a, b)	for (__typeof (b) i = (a) ; i <= b ; ++i)
#define rep(i, n)		forab (i, 0, (n) - 1)
#define For(i, n)		forab (i, 1, n)
#define rofba(i, a, b)	for (__typeof (b)i = (b) ; i >= a ; --i)
#define per(i, n)		rofba (i, 0, (n) - 1)
#define rof(i, n)		rofba (i, 1, n)
#define forstl(i, s)	for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
#define __(args...) {dbg,args; cerr<<endl;}
struct debugger{template<typename T> debugger& operator , (const T& v){cerr<<v<<"\t"; return *this; }}dbg;
#define __1D(a,n) rep(i,n) { if(i) printf(" ") ; cout << a[i] ; }
#define __2D(a,r,c,f) forab(i,f,r-!f){forab(j,f,c-!f){if(j!=f)printf(" ");cout<<a[i][j];}cout<<endl;}

template<class A, class B> ostream &operator<<(ostream& o, const pair<A,B>& p){ return o<<"("<<p.ff<<", "<<p.ss<<")";} //Pair print
template<class T> ostream& operator<<(ostream& o, const vector<T>& v){ o<<"[";forstl(it,v)o<<*it<<", ";return o<<"]";} //Vector print
template<class T> ostream& operator<<(ostream& o, const set<T>& v){ o<<"[";forstl(it,v)o<<*it<<", ";return o<<"]";} //Set print

//Fast Reader
template<class T>inline bool read(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction

/* **************************************  My code start here ****************************************** */

Long a , b , c ;

 vector < int > sv ;

int need( Long x )
{
     int digit = 0 ;
     if( x == 0 ) return 1 ;
     while( x > 0 )
     {
         x /= 7ll;
         digit += 1 ;
     }
     return digit;
}

int main()
{
   // I will always use scanf and printf
   // May be i won't be a good programmer but i will be a good human being

    c = 7ll ;
    a = LL , b = LL ;
    int mxa = need(a-1);
    int mxb = need(b-1);
    //cout << mxa << " " << mxb << endl ;
   // if( b > a ) swap( a , b );
    int total = mxa + mxb ;
    if( total > 8 )
    {
        printf("0\n");
    }
    else
    {
        Long ans = 0 ;

        for( int i = 0 ; i < a ; i++ )
        {
            int freq[10] = {0};
            sv.clear();
            int now = i ;
            int ok = 1 ;
            int tot = 0 ;
            if( now == 0 ) { freq[0] = 1 ; tot = 1 ; sv.pb(0) ;}
            while( now > 0 && ok )
            {
               if( freq[now%7ll] )
               {
                   ok = 0 ;
                   break;
               }
               else { freq[now%7ll] = 1 ; sv.pb(now%7ll);}
               now /= 7ll ;
               tot++;
            }
            if( mxa - tot > 1 ) continue ;
            if( mxa - tot == 1 && freq[0] == 1 ) continue ;
            else if( mxa - tot == 1 ) { freq[0] = 1 ; sv.pb(0);}

            if( ok == 0 ) continue ;
            for( int j = 0 ; j < b ; j++ )
            {
               // printf("i:: %d\n",i);
                int xnow = j ;
                ok = 1 ;
                //vector < int > clr ;
                int tot = 0 ;
                if( xnow == 0 && freq[0] ) continue ;
                else if( xnow == 0 )
                {

                    freq[0] = 1 ;
                    tot = 1 ;
                }
                while( xnow > 0 && ok )
                {
                    if( freq[xnow%7ll] )
                    {
                        ok = 0 ;
                        break;
                    }
                    else
                    {
                        freq[xnow%7ll] = 1 ;

                    }
                    xnow /= 7;
                    tot++;
                }
                if( mxb - tot > 1 )
                {
                    ok = 0 ;
                   // printf("if i :: %d j :: %d\n",i , j);
                }
                else if( mxb - tot == 1 && freq[0] == 1 )
                {
                    ok = 0 ;
                   // printf("else if :: i :: %d j :: %d\n",i , j);
                }

                rep( k , 10 ) freq[k] = 0 ;
                int sz = sv.size();
                rep( k , sz ) freq[sv[k]] = 1 ;
                if( ok )
                {
                    ans++;
                   // printf("i:: %d j :: %d\n" , i , j );
                }

            }
        }
        cout << ans << endl ;
    }

    return 0;
}

#include <iostream>

using namespace std;

int GetLength(int n)
{
	int length = 0;
	do
	{
		length++;
		n /= 7;
	} while (n);

	return length;
}

int d[7] = {0, 1, 2, 3, 4, 5, 6};

bool GetNext(int i)
{
	if (d[i] + 1 < 7)
	{
		d[i]++;
		return true;
	}

	if (i == 0) return false;

	d[i] = 0;
	return GetNext(i - 1);
}

bool AllDifferent(int len)
{
	int digits[7] = {};
	for (int i = 0; i < len; i++)
		digits[d[i]]++;

	for (int i = 0; i < 7; i++)
		if (digits[i] > 1)
			return false;

	return true;
}

int AsNumber(int i, int len)
{
	int number = 0;
	for (; i < len; i++)
		number = number * 7 + d[i];

	return number;
}

int main()
{
	int n, m;
	cin >> n >> m;

	int len1 = GetLength(n - 1);
	int len2 = GetLength(m - 1);
	int len = len1 + len2;

	if (len > 7) cout << 0;
	else
	{
		int total = 0;
		do
		{
			// for (int i = 0; i < len1; i++)
			// 	cout << d[i];
			// cout << '_';
			// for (int i = len1; i < len; i++)
			// 	cout << d[i];

			// cout << ' ' << AsNumber(0, len1) << ' ' << AsNumber(len1, len) << "\n";

			if (AllDifferent(len) && AsNumber(0, len1) < n && AsNumber(len1, len) < m)
				total++;
		} while (GetNext(len - 1));

		cout << total;
	}
}

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+10,M=1e6+10,inf=1e9+10;
int getnum(int x)
{
    int ans=0;
    if(x==0)
    return 1;
    while(x)
    {
        x/=7;
        ans++;
    }
    return ans;
}
int a[10]={0,1,2,3,4,5,6};
pair<int,int>p;
map<pair<int,int>,int>m;
int check(int pos,int len,int x,int y)
{
    int base=1;
    int num=0;
    for(int i=pos-1;i>=0;i--)
    {
        num+=a[i]*base;
        base*=7;
    }
    int shu=0;
    base=1;
    for(int i=len-1;i>=pos;i--)
    {
        shu+=a[i]*base;
        base*=7;
    }
    if(num<=x&&shu<=y)
    {
        if(m[make_pair(num,shu)])
        return 0;
        else
        {
            m[make_pair(num,shu)]=1;
            return 1;
        }
    }
    return 0;
}
int main()
{
    int x,y,z,i,t;
    scanf("%d%d",&x,&y);
    x--;
    y--;
    z=getnum(x)+getnum(y);
    if(z>7)
    printf("0\n");
    else
    {
        int ans=0;
        do
        {
            for(i=1;i<z;i++)
            if(check(i,z,x,y))
            {
                ans++;
            }
        }while(next_permutation(a,a+7));
        printf("%d\n",ans);
    }
    return 0;
}

#include <bits/stdc++.h>
#define int long long
#define author_by_CutieRabbit ios::sync_with_stdio(0); cin.tie(0);
#define MAX 1e18
using namespace std;

bool check(int i, int j, int n, int m){
	vector<int> vec(10);
	if(n == 0) vec[0]++;
	if(m == 0) vec[0]++;
	while(n > 0){
		vec[i % 7]++;
		n /= 7;
		i /= 7;
	}
	while(m > 0){
		vec[j % 7]++;
		m /= 7;
		j /= 7;
	}
	if(*max_element(vec.begin(), vec.end()) >= 2){
		return false;
	}
	return true;
}

int32_t main(){ author_by_CutieRabbit
	int n, m;
	cin >> n >> m;
	if(1LL*n*m >= 1e6){
		cout << 0 << endl;
		return 0;
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			ans += check(i, j, n-1, m-1);
		}
	}
	cout << ans << endl;
}

/*NAME: SANYAM GARG
INSTITUTION:DELHI TECHNOLOGICAL UNIVERSITY*/
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset>
#define mod 1000000009
using namespace std;
long long int ans=0,n,m,p,q,ar[100];
void func()
{
//	cout<<"hi";
	int i;
	int mark[7];
	for(i=0;i<7;i++)
	{
		mark[i]=0;
	}
	for(i=0;i<(p+q);i++)
	{
		mark[ar[i]]++;
	}
	int sum;
	sum=0;
	for(i=0;i<7;i++)
	{
		if(mark[i]==1)
		sum++;
	}
	long long int x=0,y=0;
	if(sum==(p+q))
	{
//		cout<<"hello";
		for(i=p+q-1;i>=q;i--)
		{
			x=x*7+ar[i];
		}
		for(i=q-1;i>=0;i--)
		{
			y=y*7+ar[i];
		}
//		cout<<n1<<" "<<m1<<endl;
			if((x<=(n)&&y<=(m)))
			{
//				cout<<"yes";
//for(i=(p+q-1);i>=0;i--)
//{
//	cout<<ar[i];
//}
				ans++;
			}
	}

}
void recs(int e)
{
	int i;
	if(e==(p+q-1))
	{
		for(i=0;i<=6;i++)
		{
		ar[e]=i;
		func();
	    }
	}
	else
	{
		for(i=0;i<=6;i++)
		{
		ar[e]=i;
		recs(e+1);
	    }
	}
}
int main()
{
long long int n1,m1,temp1,temp2;
	//make all var global
cin>>n>>m;
n=n-1;
m=m-1;
p=0;
q=0;
temp1=n;
temp2=m;
n1=0;//base 7 mein hai!!
m1=0;

while(temp1>0)
{

	n1=n1*7+temp1%7;
	temp1=temp1/7;
	p++;
}
while(temp2>0)
{

	m1=m1*7+temp2%7;
	temp2=temp2/7;
	q++;
}
//cout<<p+q<<endl;

if((p+q)>7)
{
	cout<<"0";
}
else
{
	if(p==0)
	p=1;
	if(q==0)
	q=1;
	recs(0);
	cout<<ans;
}

}

#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int n1,n2,f,ans=0,t1,t2,i,j,k,l,n,m,fir=0,sec=0;
	cin>>n>>m;
	t1=n-1,t2=m-1;
	while(t1) {
		t1/=7;
		fir++;
	}
	while(t2) {
		t2/=7;
		sec++;
	}
	if(!sec)
		sec++;
	if(!fir)
		fir++;
	long long int fl1[7];
	for(i=0;i<=1000000;i++) {
		long long int fl[7]={0};
		k = i;
		f=1;
		for(j=0;j<fir;j++) {
			if(fl[k%7]) {
				f=0;
				break;
			}
			else
				fl[k%7] = 1;
			k/=7;
		}
		if(!f||k)
			continue;
		if(i>=n)
			break;
		for(j=0;j<=1000000;j++) {
			f = 1;
			for(l=0;l<7;l++)
				fl1[l] = fl[l];
			k = j;
			if(k>=m)
				break;
			for(l=0;l<sec;l++) {
				if(fl1[k%7]) {
					f=0;
					break;
				}
				else
					fl1[k%7] = 1;
				k/=7;
			}
			if(!k&&f)
				ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

#include <iostream>
#include <list>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
const int MAX = 5 * 10000;
const int MOD = 1e9 + 7;
const double PI = 3.1415926535;

double dist1(double x1, double y1, double x2, double y2){
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
int dist(int x1, int y1, int x2, int y2){
	return (abs(x1 - x2) + abs(y1 - y2));
}

int get_pow(int n){
	int res = 0;
	while (n > 0){
		res++;
		n = n - n % 7;
		n = n / 7;
	}
	return res;
}
bool vich(bool *yes, int r,int k){
	int res = 0;
	while (r > 0){
		res++;
		int ost = r % 7;
		if (yes[ost] == true){
			return false;
		}
		else{
			yes[ost] = true;
		}
		r = r - ost;
		r = r / 7;
	}
	if (k - res >= 2)
		return false;
	else if (k - res == 1 && yes[0] == true)
		return false;
	else if (k - res == 1){
		yes[0] = true;
		return true;
	}
	else
		return true;

}

int main()
{
	int n, m;
	cin >> n >> m;
	n--; m--;
	int k = max(1,get_pow(n));
	int l = max(1,get_pow(m));
	if (k + l > 7){
		cout << 0;
	}
	else{
		int count = 0;
		for (int i = 0; i <= n; i++){
			for (int j = 0; j <= m; j++){
				bool yes[7];
				for (int p = 0; p < 7; p++){
					yes[p] = false;
				}
				bool x = vich(yes, i, k);
				if (x == true){
					x = vich(yes, j, l);
					if (x == true)
						count++;
				}
			}
		}
		cout << count;

	}
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair <int,int> pii;

#define trace(x) cout << #x << "  " << x << endl
#define fors(i, a, b) for (int i = (a); i < int(b); i++)
#define rep(i, n) fors(i, 0, n)
int rjes;
ll n,m,br1,br2,pot[110],cd,bio[200],brr1,brr2;

ll cnt(ll x){
	ll y = 0;
	while(x != 0){
		x /= 10;
		y++;
	}

	return y;
}

ll pret(ll x){
	ll z = 0;
	int flag = 0;
	for(int y = 8;y >= 0;y--){
		if(x / pot[y] != 0){
			flag = 1;

			z += x /pot[y];

			x = x % pot[y];

		}
		if(flag&&y != 0){
			z *= 10;
		}
	}

	return z;
}

int main(){

	scanf("%lld %lld",&n,&m);
	pot[0] = 1;
	fors(i,1,23){
		pot[i] = pot[i - 1] * 7;
	}
	//printf("bio %lld\n",pret(n));
	br1 = cnt(pret(n - 1));
	br2 = cnt(pret(m - 1));
	//printf("bio.. %lld %lld %lld %lld\n",br1,br2,pot[br1],pot[br2]);
	if(br1 == 0){
		brr1 = 1;
	}
	else{
		brr1 = br1;
	}
	if(br2 == 0){
		brr2 = 1;
	}
	else{
		brr2 = br2;
	}
	//printf("bio.. %lld %lld %lld %lld\n",brr1,brr2,pot[br1],pot[br2]);
	if(br1 + br2 > 7){
		printf("0");

	}
	else{

		rep(i,pot[br1]){
			rep(j,pot[br2]){
				rep(k,11){
					bio[k] = 0;
				}
				cd = 0;

				if(i < n&&j < m){

					//printf("bio1 %d %d %d %d\n",cnt(pret(i)),cnt(pret(j)),i,j);
					if((brr1 + brr2)- (cnt(pret(i)) + cnt(pret(j))) > 1){
						//printf("bio tu\n");
						continue;
					}
					else if((brr1 + brr2)- (cnt(pret(i)) + cnt(pret(j))) == 1){
						//printf("bio\n");
						bio[0]++;

					}
					ll di = pret(i);
					ll dj = pret(j);

					//printf("bio2 %lld %lld\n",di,dj);
					while(di != 0){
						bio[di % 10]++;
						if(bio[di % 10] > 1){
							cd = 1;
						}

						di /= 10;
					}

					while(dj != 0){
						bio[dj % 10]++;
						if(bio[dj % 10] > 1){
							cd = 1;
						}

						dj /= 10;
				 	}

					if(!cd&&(i != 0||j != 0)){

						rjes++;

						//1printf("%d\n",rjes);
					}
				}
			}
		}
		printf("%d\n",rjes);
	}

	return 0;
}

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

long long n, m, current = 1, power, power_n, power_m, ans;

long long convert_to_dec(string s)
{
	long long current_pow = 1LL, answer = 0, digit;

	for(long long i = s.size() - 1; i >= 0; i--)
	{
		digit = s[i] - '0';
		answer += current_pow * digit;
		current_pow *= 7LL;
	}

	return answer;
}
void brute_force(long long ind, string number)
{
	if(ind == power_n + power_m)
	{
		if(convert_to_dec(number.substr(0, power_n)) < n && convert_to_dec(number.substr(power_n)) < m)
		{
			ans++;
			//cout<<number<<endl;
		}

		return;
	}

	bool flag;
	for(int i = 0; i < 7; i++)
	{
		flag = true;
		for(int j = 0; j < number.size(); j++)
		{
			if(number[j] - '0' == i)
			{
				flag = false;
				break;
			}
		}

		if(flag) brute_force(ind + 1, number + (char)(i + '0'));
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>m;

	while(current < n)
	{
		current *= 7LL;
		power++;
	}
	power_n = power;

	current = 1LL;
	power = 0;
	while(current < m)
	{
		current *= 7LL;
		power++;
	}
	power_m = power;

	if(n == 1) power_n = 1;
	if(m == 1) power_m = 1;

	brute_force(0, "");
	cout<<ans<<endl;

	return 0;
}

#include <iostream>
using namespace std;

long long n, m, ap[100], st1[100], st2[100], rez, a, b, sp1, sp2;

void check2() {
    long long t = 0, p = 1;
    for (long long i = 1;i <= sp2;i++) {
        t += st2[i] * p;
        p *= 7;
    }
    if (t < m) rez++;
}

void back2(long long k) {
    if (k > sp2) check2();
    else {
        for (long long i = 0;i <= 6;i++) {
            if (!ap[i]) {
                st2[k] = i;
                ap[i] = 1;
                back2(k + 1);
                st2[k] = 0;
                ap[i] = 0;
            }
        }
    }
}

void check() {
    long long t = 0, p = 1;
    for (long long i = 1;i <= sp1;i++) {
        t += st1[i] * p;
        p *= 7;
    }
    if (t < n) back2(1);
}

void back(long long k) {
    if (k > sp1) check();
    else {
        for (long long i = 0;i <= 6;i++) {
            if (!ap[i]) {
                st1[k] = i;
                ap[i] = 1;
                back(k + 1);
                st1[k] = 0;
                ap[i] = 0;
            }
        }
    }
}

int main()
{
    cin >> n >> m;
    a = n;
    b = m;
    a--;
    b--;
    if (!a) a++;
    if (!b) b++;
    while (a) {
        a /= 7;
        sp1++;
    }
    while (b) {
        b /= 7;
        sp2++;
    }
    //cout << sp1;
    //cout << sp2;
    back(1);
    cout << rez;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll  x,y,p,q,a,b,n=0,m=0,c=0;
set<ll >s;
int main(){
    cin>>a>>b;
    a--; b--;p=a;q=b;
    if(p==0) n++;
    while(p){n++; p/=7;}
    if(q==0) m++;
    while(q){m++; q/=7;}
    if(n+m>7){
        cout<<0<<endl;
        return 0;
    }
    for(ll  i=0; i<=a; i++){
        for(ll  j=0; j<=b; j++){
             p=i; q=j; x=0; y=0;
             while(p ||x<n){
                s.insert(p%7);
                p/=7;x++;
             }
             while(q || y<m){
                s.insert(q%7);
                q/=7;y++;
             }
             if(s.size()==n+m) c++;
             s.clear();
        }
    }cout<<c<<endl;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <list>
#include <map>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f
#define PI 3.1415926535898
#define pb push_back
#define F first
#define S second
#define lson rt << 1
#define rson rt << 1 | 1
using namespace std;
const int MAX = 1e2 + 10;
const int MOD = 1e9 + 7;
ll qpow(ll a, ll b) //求a^b
{
    ll cnt = 1;
    while (b)
    {
        if (b & 1)
            cnt *= a;
        a *= a;
        b >>= 1;
    }
    return cnt;
}
ll len1, len2, n, m;
int vis[10];
ll dfs(int pos, ll hour, ll min)
{
    if (pos >= len1 + len2)
        return 1;
    ll rnt = 0;
    if (pos < len1)
    {
        for (int i = 0; i <= 6; i++)
        {
            ll cur = hour + i * qpow(7, len1 - pos - 1);
            if (cur >= n || vis[i])
                continue;
            vis[i] = 1;
            rnt += dfs(pos + 1, cur, min);
            vis[i] = 0;
        }
    }
    else
    {
        for (int i = 0; i <= 6; i++)
        {
            ll cur = min + i * qpow(7, len2 - (pos - len1) - 1);
            if (cur >= m || vis[i])
                continue;
            vis[i] = 1;
            rnt += dfs(pos + 1, hour, cur);
            vis[i] = 0;
        }
    }
    return rnt;
}
int main()
{
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    cin >> n >> m;
    ll tmp = n;
    while (tmp)
    {
        len1++;
        tmp /= 7;
    }
    tmp = m;
    while (tmp)
    {
        len2++;
        tmp /= 7;
    }
    tmp = 7;
    while (n > tmp)
        tmp *= 7;
    if (n == tmp)
        len1--;
    tmp = 7;
    while (m > tmp)
        tmp *= 7;
    if (m == tmp)
        len2--;
    // if (len1 + len2 > 7)
    //     cout << 0 << endl;
    // else
    cout << dfs(0, 0, 0) << endl;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef Lightning
	#define debug(orz...) printf(orz)
	const int DEBUG = 1;
#else
	#define debug(...)
	const int DEBUG = 0;
#endif

#define file_able if (0)
#define setfile(pro_name) freopen(pro_name".in", "r", stdin), freopen(pro_name".out", "w", stdout)
#define closefile() fclose(stdin), fclose(stdout)

#define cmax(_x, _y) (_x < (_y) ? _x = _y : 0)
#define cmin(_x, _y) (_x > (_y) ? _x = _y : 0)
#define gmax(_x, _y) ((_x) > (_y) ? (_x) : (_y))
#define gmin(_x, _y) ((_x) < (_y) ? (_x) : (_y))

namespace defs
{
	// #define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)

	// char B[1 << 15], *S = B, *T = B;

	#define getc() getchar()

	template <class Type> Type read()
	{
		Type aa;
		int bb = 1, ch;
		while (ch = getc(), (ch < '0' || ch > '9') && ch != '-');
		ch == '-' ? aa = 0, bb = -1 : aa = ch - '0';
		while (ch = getc(), ch >= '0' && ch <= '9') aa = aa * 10 + ch - '0';
		return bb == 1 ? aa : -aa;
	}

	const unsigned int rand_x = 11309;
	const unsigned int rand_y = 1000000019;

	unsigned int rand_cur;

	unsigned int rand_int()
	{
		return rand_cur = rand_cur * rand_x + rand_y;
	}

	const int inf = 1071026353;
	const int mod = 1000000007;
	const int modx = 998244353;
}

namespace lightningwork
{
	// my space

	int (*read)() = defs::read<int>;

	int n, m, d1, d2;

	int vis[10];

	int ans;

	int get(int x)
	{
		int ret = 0;
		while (x)
		{
			x /= 7;
			++ret;
		}
		cmax(ret, 1);
		return ret;
	}

	void dfs2(int i, int num)
	{
		if (i == 0)
		{
			if (num <= m)
			{
				++ans;
			}
		} else
		{
			for (int j = 0; j < 7; ++j)
			{
				if (vis[j] == 0)
				{
					vis[j] = 1;
					dfs2(i - 1, num * 7 + j);
					vis[j] = 0;
				}
			}
		}
	}

	void dfs(int i, int num)
	{
		if (i == 0)
		{
			if (num <= n)
			{
				dfs2(d2, 0);
			}
		} else
		{
			for (int j = 0; j < 7; ++j)
			{
				if (vis[j] == 0)
				{
					vis[j] = 1;
					dfs(i - 1, num * 7 + j);
					vis[j] = 0;
				}
			}
		}
	}

	void work()
	{
		n = read() - 1;
		m = read() - 1;
		d1 = get(n);
		d2 = get(m);
		dfs(d1, 0);
		printf("%d\n", ans);
	}
}

int main()
{
	file_able setfile("work");
	lightningwork::work();
	file_able closefile();
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define sd(x) scanf("%d",&x);
#define slld(x) scanf("%lld",&x);
#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Fill(a, b) memset(a, b, sizeof(a))
#define INF 2000000009

typedef pair<int,int> PII;
typedef vector<int> VI;

int n,m;

LL power(LL a,LL n)
{
    LL ans = 1;
    while(n > 0)
    {
        if(n&1)ans = ans*a ;
        n>>=1;
        a = a*a ;
    }
    return ans;
}

bool isdist(int num, int len1,int len2)
{
    int vis[7] = {0},tmp=0;
    while(len1 > 0)
    {
        if(vis[num%7])return false;
        vis[num%7] = 1;
        tmp = tmp*7 + (num%7);
        num/=7;
        len1--;
    }
    //cout<<"func "<<tmp<<endl;
    if(tmp > n)
    {
        return false;
    }
    tmp = 0;
    while(len2 > 0)
    {
        if(vis[num%7])return false;
        vis[num%7] = 1;
        tmp = tmp*7 + (num%7);
        num/=7;
        len2--;
    }
    //cout<<tmp<<endl;
    if(tmp > m)return false;
    return true;
}

void solve()
{
    int len1 = 0,len2= 0,tn,tm;
    sd(n);sd(m);
    n--;m--;
    tn = n,tm = m;
    while(tn>0)
    {
        tn/=7;
        len1++;
    }
    while(tm>0)
    {
        tm/=7;
        len2++;
    }
    len1 = max(1,len1);
    len2 = max(1,len2);
    int len= len1+len2;
    //cout<<len<<endl;
    if(len > 7)
    {
        cout<<"0\n";
        return;
    }
    int pn = power(7,len);
    int ans = 0;
    //cout<<pn<<endl;
    for(int i=0;i<pn;i++)
    {
        if(isdist(i,len1,len2))
        {
            //cout<<"val "<<i<<endl;
            ans++;
        }
    }
    cout<<ans<<endl;
}

int main()
{
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++)
	{
		solve();
	}
}

#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;

typedef long long ll;

int ns[30], ms[30];
int nsize, msize;
int nsc[30], msc[30];

void convert(int x, int s[], int& size) {
    if (x == 0) {
        size = 1;
        return;
    }

    int cnt = 0;
    while (x) {
        int rem = x%7;
        x = x / 7;
        s[cnt++] = rem;
    }

    size = cnt;
    // cnt = cnt/2;
    // for (int i = 0; i < cnt; i++)
    //     swap(s[i], s[size-i-1]);
}

int sum(int sc[], int &size) {
    int change = 1;
    for (int i = 0; i < size && change; i++) {
        sc[i] += change;
        change = sc[i]/7;
        sc[i] = sc[i] % 7;
    }
}

int lss(int sc[], int s[], int &size) {
    for (int i = size-1; i >= 0; i--) {
        if (sc[i] < s[i]) return 1;
        else if (sc[i] > s[i]) return 0;
    }
    return 2;
}

void prints() {
    printf("nsc: ");
    for (int i = nsize-1; i>=0; i--)
        printf("%d", nsc[i]);

    printf("\n");

    printf("msc: ");
    for (int i = msize-1; i>=0; i--)
        printf("%d", msc[i]);
    printf("\n");
}

ll check()
{
    int used[7] = {0,0,0,0,0,0,0};
    bool ok = 1;

    for (int i = 0; i < nsize; i++)
        used[nsc[i]]++;

    for (int i = 0; i < msize; i++)
        used[msc[i]]++;

    for (int i = 0; i < 7; i++)
        if (used[i] > 1) ok = 0;

    if (ok)
        return 1LL;
    else
        return 0LL;
}

int main()
{
    ll n, m;
    scanf("%lld %lld", &n, &m);
    n--; m--;

    convert(n, ns, nsize);
    convert(m, ms, msize);

    // for (int i = 0; i < nsize;i++)
        // printf("%d", ns[i]);
    // printf("\n");

    // nsc[0] = 2;nsc[1] = 1; nsc[2] = 0;
    // msc[0] = 6;msc[1] = 5; msc[2] = 4; msc[3] = 3;

    // prints();
    // printf("nsize %d msize%d\n", nsize, msize);

    ll ans = 0;
    int op1 = lss(nsc, ns,nsize);
    int op2 = lss(msc, ms,msize);
    // prints();
    // printf("op %d %d\n", op1, op2);
    // printf("checked\n");
    if (nsize + msize <= 7) {
        while (1) {
            for (int i = 0; i < msize; i++)
                msc[i] = 0;
            op2 = lss(msc, ms, msize);

            while (1) {
                // prints();
                // printf("check: %d\n", check());
                ans += check();
                if(op2 == 2) break;
                sum(msc, msize);
                op2 = lss(msc, ms, msize);
            }

            if (op1 == 2) break;
            sum(nsc, nsize);
            op1 = lss(nsc, ns, nsize);
        }
    }

end:   printf("%lld\n", ans);
}

#include <bits/stdc++.h>
using namespace std;
int base_7_digit(int n){
  if (n < 7){
    return 1;
  } else {
    return base_7_digit(n / 7) + 1;
  }
}
int pow7(int n){
  if (n == 0){
    return 1;
  } else {
    return pow7(n - 1) * 7;
  }
}
int to_dec(string S){
  int N = S.size();
  int ans = 0;
  for (int i = 0; i < N; i++){
    ans *= 7;
    ans += S[i] - '0';
  }
  return ans;
}
int main(){
  int n, m;
  cin >> n >> m;
  int d1 = base_7_digit(n - 1);
  int d2 = base_7_digit(m - 1);
  if (d1 + d2 > 7){
    cout << 0 << endl;
  } else {
    int d = d1 + d2;
    int t = pow7(d);
    int ans = 0;
    for (int i = 0; i < t; i++){
      int tmp = i;
      string S;
      for (int j = 0; j < d; j++){
        S += tmp % 7 + '0';
        tmp /= 7;
      }
      vector<bool> used(7);
      bool ok = true;
      for (int j = 0; j < d; j++){
        if (used[S[j] - '0']){
          ok = false;
        }
        used[S[j] - '0'] = true;
      }
      if (ok){
        string S1 = S.substr(0, d1);
        string S2 = S.substr(d1);
        int a = to_dec(S1);
        int b = to_dec(S2);
        if (a < n && b < m){
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <cstring>

using namespace std;

int len_in_dec(int v){
    if(v==0){
        return 1;
    }
    int len = 0;
    while(v){
        v/=7;
        len++;
    }
    return len;
}

int pow(int x, int k){
    int result = 1;
    while(k--){
        result *= x;
    }
    return result;
}

signed main(){
    int n;
    int m;
    cin >> n >> m;
    int n_len = len_in_dec(n-1);
    int m_len = len_in_dec(m-1);
    int total_len = n_len + m_len;
    if(total_len > 7){
        cout << 0 << endl;
        return 0;
    }
    int state_cnt_n = pow(7, n_len);
    int state_cnt_m = pow(7, m_len);
    int cntnum[7] = {0};
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            memset(cntnum, 0, sizeof(cntnum));
            int ti = i;
            int tj = j;
            bool valid = true;
            int cnt = 0;
            while(ti){
                if(cntnum[ti%7]){
                    valid = false;
                    break;
                }
                cntnum[ti%7]=1;
                ti/=7;
                cnt++;
            }
            if(valid)
            while(tj){
                if(cntnum[tj%7]){
                    valid = false;
                    break;
                }
                cntnum[tj%7]=1;
                tj/=7;
                cnt++;
            }
            if(valid)
                if((total_len - cnt > 1 && cntnum[0]==0) || (total_len - cnt > 0 && cntnum[0]==1) )
                    valid = false;
            if(valid){
                ans++;
        //        cout << i << "," << j << endl;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#define eps 1e-8
#define LL long long
using namespace std;
bool vis[7];
bool check(int num1,int num2,int cnt1,int cnt2)
{
    memset(vis,0,sizeof(vis));
    while(cnt1)
    {
        int x=num1%7;
        if(vis[x])
            return false;
        vis[x]=1;
        num1/=7;
        cnt1--;
    }
    while(cnt2)
    {
        int x=num2%7;
        if(vis[x])
            return false;
        vis[x]=1;
        num2/=7;
        cnt2--;
    }
    return true;
}
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        int cnt1=0,cnt2=0;
        int temp1=n-1,temp2=m-1;
        while(temp1)
        {
            cnt1++;
            temp1/=7;
        }
        while(temp2)
        {
            cnt2++;
            temp2/=7;
        }
        if(n==1)
            cnt1=1;
        if(m==1)
            cnt2=1;
        if(cnt1+cnt2>7)
        {
            cout<<0<<endl;
            continue;
        }
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(check(i,j,cnt1,cnt2))
                    cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n,m;
ll ans=0;
vector<int> vn,vm;
int len1,len2;
bool vis[12];

void rdfs(bool limit,int dep) {
	if(dep==len2) {
		ans++;
		return;
	}
	int end=limit?vm[len2-dep-1]:6;
	for(int i=0; i<=end; i++) {
		if(vis[i])continue;

		vis[i]=1;
		rdfs(limit&&i==vm[len2-dep-1],dep+1);
		vis[i]=0;
	}
}

void dfs(bool limit,int dep) {
	if(dep==vn.size()) {
		rdfs(1,0);
		return;
	}
	int end=limit?vn[len1-dep-1]:6;
	for(int i=0; i<=end; i++) {
		if(vis[i])continue;
		vis[i]=1;
		dfs(limit&&i==vn[len1-dep-1],dep+1);
		vis[i]=0;
	}
}

int main() {
	scanf("%d%d",&n,&m);
	n--,m--;
	int t=n;
	while(t>0) {
		vn.push_back(t%7);
		t/=7;
	}
	if(vn.empty())vn.push_back(0);
	len1=vn.size();
	t=m;
	while(t>0) {
		vm.push_back(t%7);
		t/=7;
	}
	if(vm.empty())vm.push_back(0);
	len2=vm.size();

	dfs(1,0);
	printf("%d",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool Chkmin(T &x, T y) { return x > y ? x = y, true : false; } template <class T> inline bool Chkmax(T &x, T y) { return x < y ? x = y, true : false; } template <class T> inline T read(T &x) { static char c; static int f; for (f = 1; !isdigit(c = getchar()); ) if (c == '-') f = -f; for (x = 0; isdigit(c); c = getchar()) x = x * 10 + c - 48; return x *= f; } template <class T> inline void write(T x, char P = 0) { static int top = 0; static char s[25]; if (x < 0) putchar('-'), x = -x; do s[++top] = x % 10 + 48; while (x /= 10); do putchar(s[top]); while (-- top); if (P) putchar(P); } int N, M; int ans; int cnt1, cnt2; int vis[10], base[10]; void DFS(int x, int y, int k) { if (x >= N || y >= M) return; if (k == cnt1 + cnt2) { ans ++; return ; } for (int i = 0; i < 7; ++ i) if (!vis[i]) { if (k < cnt1) x += base[k] * i; else y += base[k - cnt1] * i; vis[i] = 1; DFS(x, y, k + 1); vis[i] = 0; if (k < cnt1) x -= base[k] * i; else y -= base[k - cnt1] * i; } } int main() { cin >> N >> M; int tmp = N - 1; while (tmp) { cnt1 ++; tmp /= 7; } tmp = M - 1; while (tmp) { cnt2 ++; tmp /= 7; } Chkmax(cnt1, 1); Chkmax(cnt2, 1); base[0] = 1; for (int i = 1; i <= 7; ++ i) base[i] = base[i - 1] * 7; if (cnt1 + cnt2 > 7) cout << 0 << endl, exit(0); DFS(0, 0, 0); cout << ans; }

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int size(int a)
{
	if(a==0)
	return 1;
	int t=0;
	while(a>0)
	{
		t++;
		a/=7;
	}
	return t;
}
bool diff(int a[],int b[],int asize,int bsize)
{
	set <int> s;
	int i;
	for(i=0;i<asize;i++)
	s.insert(a[i]);
	for(i=0;i<bsize;i++)
	s.insert(b[i]);
	if(s.size()==asize+bsize)
	return true;
	return false;
}
void add(int arr[],int s)
{
	int i;
	for(i=s-1;i>=0;i--)
	{
		arr[i]++;
		if(arr[i]<7)
		return;
		arr[i]=0;
	}
}
int main()
{
	int m,n,count=0,msize,nsize,h,min,i,j,k;
	cin>>m>>n;
	msize=size(m-1);
	nsize=size(n-1);
	if(msize+nsize>7)
	{
		cout<<0;
		return 0;
	}
	int arrm[msize]={0};
	for(i=0;i<m;i++)
	{
		int arrn[nsize]={0};
		for(j=0;j<n;j++)
		{
			//for(k=0;k<msize;k++)
			//cout<<arrm[k];
		//	cout<<" ";
			//for(k=0;k<nsize;k++)
			//cout<<arrn[k];
			//cout<<endl;
			if(diff(arrm,arrn,msize,nsize)){
			count++;}//cout<<"yes";}
			add(arrn,nsize);
		}
		add(arrm,msize);
	}
	cout<<count;
}

#include<bits/stdc++.h>
using namespace std;
long long power(long long x, long long y)
{
    int temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}
int test(long long i,long long j,long long n,long long m)
{
    long long temp[7]={0};
    while(i)
    {
        temp[i%7]++;
        i/=7;
        n--;
    }
    while(n>0)
    {
        temp[0]++;
        n--;
    }
    while(j)
    {
        temp[j%7]++;
        j/=7;
        m--;
    }
    while(m>0)
    {
        temp[0]++;
        m--;
    }
    for(int q=0;q<7;q++)
    {
        if(temp[q]>1)
            {
                return 0;
                //break;
            }
    }
    return 1;
}
int main()
{
    long long n,m;
    cin>>n>>m;
    long long x,y,c1=0,c2=0;
    x=n;
    y=m;
    bool f1=0,f2=0;
    for(long long i=1;i<=10;i++)
    {
        if(power(7,i)==n)
        {
            c1=i;
            f1=1;
            break;
        }
    }
    for(long long i=1;i<=10;i++)
    {
        if(power(7,i)==m)
        {
            c2=i;
            f2=1;
            break;
        }
    }

    while(x>=7&&f1==0)
    {
        c1++;
        x/=7;

    }
    if(f1==0)
    c1++;

    while(y>=7&&f2==0)
    {
        c2++;
        y/=7;

    }
    if(f2==0)
    c2++;
    //cout<<c1<<" "<<c2<<endl;

    if(c1+c2>7)
    {
        cout<<"0"<<endl;
    }
    else
    {
        long long counter=0;
        if(n!=0&&m!=0){
        for(long long i=0;i<n;i++)
        {
            for(long long j=0;j<m;j++)
            {
                if(test(i,j,c1,c2))
                    counter++;
            }
        }
        }
        else if(n==0)
        {
            for(long long j=0;j<m;j++)
            {
                if(test(0,j,1,c2))
                    counter++;
            }
        }
        else if(m==0)
        {

            for(long long i=0;i<n;i++)
            {
                if(test(i,0,c1,1))
                {
                    counter++;
                }
            }
        }
        cout<<counter<<endl;
    }
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a>b?b:a)
using namespace std;
//typedef __int64 ll;
//typedef long long ll;

int count (int num)
{
	int cnt = 0;
	while(num)
	{
		num/=7;
		cnt++;
	}
	return Max(cnt,1);
}

int main()
{
	int m,n;
	cin >> n >> m;
	int cnt1 = count(n-1);
	int cnt2 = count(m-1);

	if(cnt1+cnt2>7) printf("0\n");
	else
	{
		int ans = 0;
		for(int i  = 0; i < n; i++)
		{
			for(int j = 0; j < m ; j++)
			{
				int f[7] = {0};
				for(int num = i,k = 0;k<cnt1;k++,num/=7) f[num%7]++;
				for(int num = j,k = 0;k<cnt2;k++,num/=7) f[num%7]++;
				bool flag = true;
				for(int k = 0; k < 7; k++)
				{
					if(f[k]>1)
					{
						flag = false;
						break;
					}
				}
				if(flag) ans++;
			}
		}
		 printf("%d\n",ans);
	}
	return 0;
}

#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <random>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define MP(x, y) make_pair((x),(y))
#define FI first
#define SE second
#define LOWB(x) (x & (-x))
#define UNIQUE(a) sort(ALL(a)), (a).erase(unique(ALL(a)), (a).end())
#define HEIGHT(n) (sizeof(int) * 8 - __builtin_clz(n)) //height of range n segment tree
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<class T> inline T min(T a, T b, T c) {return min(min(a,b),c);}
template<class T> inline T min(T a, T b, T c, T d) {return min(min(a,b),min(c,d));}
template<class T> inline T max(T a, T b, T c) {return max(max(a,b),c);}
template<class T> inline T max(T a, T b, T c, T d) {return max(max(a,b),max(c,d));}
const int INF = 1e9;
const ll INF_LL = 4e18;
const double pi = acos(-1.0);
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
/*-----------------------------------*/
ll n, m, cn[1<<7], cm[1<<7];
int p[1<<7];

int dfs(int msk, int tot, int big) {
    if (msk == 0) return tot < big;
    int res = 0;
    int tmp = msk;
    while (tmp) {
        int c = LOWB(tmp);
        int nxt = tot * 7 + p[c];
        if (nxt < big)
            res += dfs(msk - c, nxt, big);
        tmp -= c;
    }
    return res;
}

int cnt_bit(int v, int base) {
    if (!v) return 1;
    int res = 0;
    while (v) {
        v /= base;
        res++;
    }
    return res;
}

int cnt_one(int v) {
    int res = 0;
    while (v) {
        res++;
        v -= LOWB(v);
    }
    return res;
}

bool valid(int msk, int big) {
    if (cnt_bit(big-1, 7) != cnt_one(msk)) return false;
    return true;
}

void init() {
    for (int i=0; i<7; i++) p[1 << i] = i;
    for (int msk=1; msk < (1<<7); msk++) {
        if (valid(msk, n))
            cn[msk] = dfs(msk, 0, n);
        if (valid(msk, m))
            cm[msk] = dfs(msk, 0, m);
    }
}

ll calc() {
    ll ans = 0;
    for (int msk=1; msk < (1<<7); msk++) {
        for (int sub=msk; sub; sub = msk & (sub - 1)) {
            ans += cn[sub] * cm[msk-sub];
        }
    }
    return ans;
}

int main() {
    cin >> n >> m;
    init();
    ll ans = calc();
    cout << ans << endl;
    return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>

using namespace std;

typedef long long inl;

bool is[7];
inl al;
inl a[7];
inl cnt = 0;

inl f(inl n)
{
	if (n == 1)
		return 1;
	return ceil(log((double)n) / log(7.));
}

inl pow7(inl x)
{
	inl a = 1;
	for (inl i = 0; i < x; i++)
		a *= 7;
	return a;
}

void gen(inl c, inl cn, inl cm, inl n, inl m)
{
	if (c == al)
	{
		inl rn = 0;
		inl rm = 0;
		for (inl i = 0; i < al; i++)
		{
			if (i < cn)
			{
				rn += a[i] * pow7((cn - 1) - i);
			}
			else
			{
				rm += a[i] * pow7((cn + cm - 1) - i);
			}
		}
		if (0 <= rn && rn < n && 0 <= rm && rm < m)
		{
			cnt++;
			/*for (int i = 0; i < cn; i++)
				cout << a[i];
			cout << ":";
			for (int i = cn; i < cn + cm; i++)
				cout << a[i];
			cout << endl;*/
		}
		return;
	}

	for (inl i = 0; i < 7; i++)
	{
		if (!is[i])
		{
			is[i] = true;
			a[c] = i;
			gen(c + 1, cn, cm, n, m);
			is[i] = false;
		}
	}
}

int main()
{
	//freopen("input.in", "r", stdin);

	inl n, m;
	cin >> n >> m;

	inl cn = f(n), cm = f(m);

	al = cn + cm;

	gen(0, cn, cm, n, m);

	cout << cnt;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9+7;
int cnt(vector<int>& d, vector<bool>& f, int t, int k, int n, int m){
  if(d.size() == t + k){
    //for(int i = 0; i < d.size(); i++)
      //cout << d[i] << ' ';
    //cout << "--" << endl;
    int q = 0, flag = 1;
    for(int i = 0; i < t; i++){
      q = q * 7 + d[i];
    }
    if(q >= n) flag = 0;
    q = 0;
    for(int i = t; i < t + k; i++)
      q = q * 7 + d[i];
    if(q >= m) flag = 0;
    return flag;
  }
  int r = 0;
  for(int i = 0; i < f.size(); i++){
    if(!f[i]){
      f[i] = 1;
      d.push_back(i);
      r += cnt(d, f, t, k, n, m);
      d.pop_back();
      f[i] = 0;
    }
  }
  return r;
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int p, q;
  cin >> p >> q;
  int n = p-1, m = q-1;
  vector<int> a, b;
  while(n > 0){
    a.push_back(n % 7);
    n /= 7;
  }
  while(m > 0){
    b.push_back(m % 7);
    m /= 7;
  }
  if(a.size() == 0)
    a.push_back(0);
  if(b.size() == 0)
    b.push_back(0);
  if(a.size() + b.size() > 7 ){
    cout << 0 << endl;
    return 0;
  }
  vector<bool> f(7);
  vector<int> d;
  cout << cnt(d, f, a.size(), b.size(), p, q) << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m1;
  cin>>n>>m1;
  int len1=1,len2=1;
  for(int i=7;i<n;i*=7)
    len1++;
  for(int i=7;i<m1;i*=7)
    len2++;
  int ans=0;
  if(len1+len2<=7)
  {
    for(int i=0;i<n;i++)
    {
      for(int j=0;j<m1;j++)
      {
        vector<int>m(7,0);
        for(int a=i,k=0;k!=len1;k++,a=a/7)
        {
          m[a%7]++;
        }
        for(int a=j,k=0;k!=len2;k++,a=a/7)
        {
          m[a%7]++;
        }
      vector<int>::iterator q=max_element(m.begin(),m.end());
        if(*q<=1)
          ans++;
      }
    }
  }
  cout<<ans;
}

#include <bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double
#define db double
#define str string
#define int long long

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>

#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18;
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

int32_t main()
{
    int n,m;
    cin>>n>>m;
    int len1=1,len2=1;
    int a=7;
    while(a<n)
    {
        len1++;
        a*=7;
    }
    a=7;
    while(a<m)
    {
        len2++;
        a*=7;
    }
    //cout<<len1<<" "<<len2<<"\n";
    if((len1+len2>7))
    {
        cout<<0<<"\n";
        return 0;
    }
    int res=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            map< int,int > mp;
            int c1=i,c2=j;
            int l1=0,l2=0;
            while(l1<len1)
            {
            //cout<<(c1%7)<<"\n";
                mp[c1%7]++;
                c1/=7;
                l1++;
            }
            while(l2<len2)
            {
                //cout<<(c2%7)<<"\n";
                mp[c2%7]++;
                c2/=7;
                l2++;
            }
            /*if(l1<len1)
             mp[0]++;
            if(l2<len2)
             mp[0]++;*/
            int f=1;
            for(int k=0;k<7;k++)
            {
                if(mp[k]>1)
                {
                    f=0;
                    break;
                }
            }
            if(f)
            {
              //cout<<i<<" "<<j<<"\n";
             res++;
             }
        }
    }
    cout<<res<<"\n";
    return 0;
}

// Author -> Preeyadarshee Dev
// nik was love.
// nik is motivation.
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                   0.000000000000001
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define endl                 '\n'
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[300010],adj1[300010];
vector<int> dis(200010),vis(300010,0);
int myrandom (int i) { return std::rand()%i;}
ll n,m;
ll cnt=0,cnt1=0,cnt2=0;
void solve(string v,ll len)
{
    if(len==(int)v.length())
    {
        ll i=0,num=0;
        while(i<cnt1)
        {
            num=num*7+v[i]-'0';
            i++;
        }
        if(num<n)
        {
            num=0;
            while(i<(int)v.length())
            {
                num=num*7+v[i]-'0';
                i++;
            }
            if(num<m)
            {
                cnt++;
            }
        }
        return ;
    }
    set<char> st={'0','1','2','3','4','5','6'};
    for(int i=0;i<(int)v.length();i++)
    {
        st.erase(v[i]);
    }
    for(auto i:st)
    {
        string t=v;
        t.pb(i);
        solve(t,len);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    cin>>n>>m;
    long long temp=n-1;
    vector<int> bt;
    if(temp==0)
    {
        bt.pb(0);
    }
    while(temp)
    {
        bt.pb(temp%7);
        temp=temp/7;
    }
    cnt1=(int)bt.size();
    reverse(all(bt));
    vector<int> ct;
    temp=m-1;
    if(temp==0)
    {
        ct.pb(temp);
    }
    while(temp)
    {
        ct.pb(temp%7);
        temp=temp/7;
    }
    reverse(all(ct));
    cnt2=(int)ct.size();
    if(cnt1+cnt2>7)
    {
        cout<<0<<endl;
    }
    else
    {
        string s;
        solve(s,cnt1+cnt2);
        cout<<cnt<<endl;
    }
}

#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define x first
#define y second
#define sqr(a) ((a)*(a))
#define pb push_back
#define mp make_pair
#define el "\n"
#define fin(i,n) for(i=0;i<n;++i)
#define bs ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

ll n,m,nn,mm,kol1,kol2,a[1000],ans1,ans2,ans;

bool used[10];

void rec2(ll v,ll sum,ll st)
{
    if(v>kol2)
    {
        if(sum<m)
           {
               ++ans2;
           }
        return;
    }
    for(int i=0;i<7;++i)
    {
        if(!used[i])
        {
            used[i] = true;
            rec2(v+1,sum+st*i,st*7);
            used[i] = false;
        }
    }
}

void rec1(ll v,ll sum,ll st)
{
    if(v>kol1)
    {
        if(sum<n)
        {
            ans2 = 0;
            rec2(1,0,1);
            ans+=ans2;
        }
        return;
    }
    for(int i=0;i<7;++i)
    {
        if(!used[i])
        {
            used[i] = true;
            rec1(v+1,sum+st*i,st*7);
            used[i] = false;
        }
    }
}

int main()
{
    //bs;
    cin>>n>>m;
    nn = n-1;
    mm = m-1;
    while(nn>=0)
    {
        nn/=7;
        kol1++;
        if(nn==0)break;
    }
    while(mm>=0)
    {
        mm/=7;
        kol2++;
        if(mm==0)break;
    }
    rec1(1,0,1);
    rec2(1,0,1);
    cout<<ans;
}

#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<int, int>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 3e2 + 10, mlg = 20, mod = 1e9 + 7;
ll n, m, a[10];
ll len(ll x) {
	if(!x) return 1;
	ll lenn = 0;
	while(x) lenn++, x/=7;
	return lenn;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	ll x = len(n-1), y = len(m-1);
	if(x+y > 7) return cout << 0, 0;
	for(int i = 0; i < 7; i++) a[i] = i;
	ll ans = 0;
	do {
		ll p = 0, q = 0;
		for(int i = 0; i < x; i++)
			p = (p*7)+a[i];
		for(int i = x; i < x+y; i++)
			q = (q*7)+a[i];
		if(p<n&&q<m) ans++;
	} while(next_permutation(a, a+7));
	for(int i = 1; i <= 7-x-y; i++)
		ans/=i;
	cout << ans;
	return 0;
}

/*
"IF U BELIEVE WHY NOT!!"
                       --Cristiano Ronaldo
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli M=100000000;
#define INF 1000000007
#define bip(n) __builtin_popcount(n)
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
lli n,k,m;
lli z,q,u,l,r,ax,cx,ay,by,cy,ql,qr,d,x,y;
//unordered_map<pair<ll,lli>,lli> mp;
string s;
lli a[500005];
lli vis[500005];
lli me(lli a,lli b,lli M)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    return me((a*a)%M,b/2,M);
    else
    return (a%M*me((a*a)%M,(b-1)/2,M)%M)%M;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
lli pi[400000];
map<lli,lli> ml,ml1;
string pf(string s,lli d)
{
    pi[0]=0;
    for(int j=1;j<s.length();j++)
    {
        int i=pi[j-1];
        if(s[j]!='?')
        {
        while(i>0&&s[j]!=s[i])
        i=pi[i-1];
        }
        else
        {
            while(i>0&&s[i]=='$')
            i=pi[i-1];
            s[j]=s[i];
        }
        if(s[i]==s[j])
        i++;
        pi[j]=i;
    }
    return s;
}
struct edge
{
    lli first,second,third;
}p[400000];
bool cmp(edge a,edge b)
{
    if(a.second==b.second)
    return a.third<b.third;
    return a.second<b.second;
}
set<lli> s2;
lli tot;
lli ccc=0;
lli n1,m1;
void solve(lli n,lli c,lli s,lli s1)
{
    if(n==0)
    {
        if(s2.size()==tot)
        {
            if(s<=n1&&s1<=m1)
            {
                //cout<<s<<" "<<s1<<endl;
                ccc++;
            }
        }
        return;
    }
    if(n>c)
    {
    for(int i=0;i<=6;i++)
    {
     if(s2.count(i))
     continue;
     s2.insert(i);
     solve(n-1,c,(s+i*pow(7,n-c-1)),s1);
     s2.erase(i);
    }
    }
    else
    {
    for(int i=0;i<=6;i++)
    {
     if(s2.count(i))
     continue;
     s2.insert(i);
     solve(n-1,c-1,s,(s1+i*pow(7,c-1)));
     s2.erase(i);
    }
    }
}
int main()
{
cin>>n>>m;
n1=n-1;
m1=m-1;
n--;
m--;
lli cnt=0;
lli cnt1=0;
if(n==0)
cnt=1;
if(m==0)
cnt1=1;
while(n>0)
{
    n=n/7;
    cnt++;
}
while(m>0)
{
    m=m/7;
    cnt1++;
}
//cout<<cnt<<" "<<cnt1<<endl;
if((cnt+cnt1)>7)
return cout<<0,0;
tot=cnt+cnt1;
solve(cnt+cnt1,cnt1,0ll,0ll);
cout<<ccc;
}//

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int a[109];

map<pair<int,int>,bool> mm;
int wein,weim;
int getv(int x){
    if(x==0) return 1;
    int res=0;
    while(x) ++res,x/=10;
    return res;
}
int n,m;
bool check(int len,int pos,int f,int s,int hf,int hs,bool zerof,bool zeros){
    if(hf>=n||hs>=m) return 0;
    if(mm.count({f,s})) return 0;
    int lenf=getv(f),lens=getv(s);
    int chaf=wein-lenf,chas=weim-lens;
    //cout<<chaf<<" "<<chas<<" "<<zerof<<" "<<zeros<<" "<<f<<" "<<s<<endl;
    if(zerof||zeros){
        if(chaf||chas) return 0;
    }
    else{
        if(chaf&&chas) return 0;
        else if(chaf>=2||chas>=2) return 0;
    }
    mm[{f,s}]=1;
    //cout<<len<<" "<<pos<<" "<<f<<" "<<s<<endl;
    return 1;
}

int main(){
    ll res=0;
    scanf("%d%d",&n,&m);
    wein=weim=1;
    ll hh=7,hhh=7;
    while(hh<n){
        ++wein;
        hh*=7;
    }
    while(hhh<m){
        ++weim;
        hhh*=7;
    }
    for(int len=3;len<=8;++len){
        int num=-1;
        for(int i=1;i<=8;++i) a[i]=num++;

        do{
            if(a[1]==-1) continue;
            int pos=-1;
            for(auto i=1;i<=8;++i) if(a[i]==-1) pos=i;
            if(pos>=len) continue;
            int f=0,s=0,hf=0,hs=0;
            bool zerof=0,zeros=0;
            for(int i=1;i<pos;++i) {f=f*10+a[i],hf=hf*7+a[i];if(a[i]==0) zerof=1;}
            for(int i=pos+1;i<=len;++i) {s=s*10+a[i],hs=hs*7+a[i];if(a[i]==0) zeros=1;}
            res+=check(len,pos,f,s,hf,hs,zerof,zeros);
        }while(next_permutation(a+1,a+1+8));
    }
    printf("%I64d\n",res);

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int ar[7];

int cnt=0;

string hr,mn;

void rec(string& s)
{

    if(s.length()==hr.length()+mn.length())
    {

        //cout<<s<<endl;

        string t;

        for(int i=0;i<hr.length();i++)
        {
            t.push_back(s[i]);
        }

        if(t>hr)
        {
            return;
        }

        t.clear();

        for(int i=0;i<mn.length();i++)
        {
            t.push_back(s[hr.length()+i]);
        }

        if(t>mn)
        {
            return;
        }

        cnt++;

        return;

    }

    for(int i=0;i<7;i++)
    {
        if(!ar[i])
        {
            ar[i]=1;
            s.push_back('0'+i);
            rec(s);
            s.pop_back();
            ar[i]=0;
        }
    }

    return;

}

int main()
{

int n,m;
scanf("%d %d",&n,&m);

n--;
m--;

if(n==0)
{
    hr.push_back('0');
}

if(m==0)
{
    mn.push_back('0');
}

while(n>0)
{
    hr.push_back('0'+n%7);
    n/=7;
}

while(m>0)
{
    mn.push_back('0'+m%7);
    m/=7;
}

if(hr.length()+mn.length()>7)
{
    printf("0\n");
    return 0;
}

reverse(hr.begin(),hr.end());
reverse(mn.begin(),mn.end());

//cout<<hr<<endl<<mn<<endl;

string s;

rec(s);

printf("%d\n",cnt);

return 0;
}

/****** BISMILLAH HIR RAHMANIR RAHIM ******/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef unsigned int ul;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef map<string,string> mss;
typedef map<int, vector<int> > mvii;
typedef map<int, int> mii;
typedef queue <int> qi;
typedef map <int, vector<string> > mvis;
typedef map <string, vector<int> > mvsi;
typedef vector <string> vs;
typedef pair <int, int> pii;

// Order Statistic Tree

/* Special functions:

		find_by_order(val) --> returns iterator to the kth largest element counting from 0
		order_of_key(val) --> returns the number of items in a set that are strictly smaller than our item
*/

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

#define MP make_pair
#define SORT(a) sort (a.begin(), a.end())
#define REVERSE(a) reverse (a.begin(), a.end())
#define ALL(a) a.begin(), a.end()
#define PI acos(-1)
#define ms(x,y) memset (x, y, sizeof (x))
#define INF 2000000000
#define pb push_back
#define MAX 100002
#define debug cout<<"A"<<"\n"
#define prnt(a) cout<<a<<"\n"
#define mod 1000000007LL
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define FORr(i,a,b) for (int i=(a); i>=b; i--)
#define itrALL(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define lc ((node)<<1)
#define rc ((node)<<1|1)
#define VecPrnt(v) FOR(j,0,v.size()) cout<<v[j]<<" "; cout<<endl
#define endl "\n"
#define PrintPair(x) cout<<x.first<<" "<<x.second<<endl

/* Direction Array */

// int fx[]={1,-1,0,0};
// int fy[]={0,0,1,-1};
// int fx[]={0,0,1,-1,-1,1,-1,1};
// int fy[]={-1,1,0,0,1,1,-1,-1};

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}

template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
template <class T, class X> inline bool getbit(T a, X i) { T t=1; return ((a&(t<<i))>0);}
template <class T, class X> inline T setbit(T a, X i) { T t=1;return (a|(t<<i)); }
template <class T, class X> inline T resetbit(T a, X i) { T t=1;return (a&(~(t<<i)));}

inline ll power(ll a, ll b)
{
	ll multiply=1;
	FOR(i,0,b)
	{
		multiply*=a;
	}
	return multiply;
}

/****** END OF HEADER ******/

vector<string> h, mn;
int n, m;
int x, y;

int to7(int val)
{
	string temp="";
	if(val==0) return 0;

	while(val>0)
	{
		temp+=char(val%7+'0');
		val/=7;
	}
	REVERSE(temp);
	return stoi(temp);
}

void go1(int pos, int d, int lim, string val)
{
	if(pos==lim) return;
	if(val.size()==x)
	{
		if(stoi(val)<to7(n))
		{
			h.pb(val);
		}
	}

	for(int i=0; i<7; i++)
	{
		go1(pos+1,i,lim,val+char(i+'0'));
	}
}

void go2(int pos, int d, int lim, string val)
{
	if(pos==lim) return;
	if(val.size()==y)
	{
		if((stoi(val))<to7(m))
			mn.pb(val);
	}

	for(int i=0; i<7; i++)
	{
		go2(pos+1,i,lim,val+char(i+'0'));
	}
}

bool check(string a, string b)
{
	int cnt[9]; ms(cnt,0);

	FOR(i,0,a.size()) cnt[a[i]-'0']++;
	FOR(i,0,b.size()) cnt[b[i]-'0']++;

	FOR(i,0,7) if(cnt[i]>1) return false;
	return true;
}

int main()
{
	// ios_base::sync_with_stdio(0);
	// cin.tie(NULL); cout.tie(NULL);
	// freopen("in.txt","r",stdin);

	cin>>n>>m;

	int temp1=n, temp2=m;

	while(temp1>0)
	{
		x++;
		temp1/=7;
	}

	while(temp2>0)
	{
		y++;
		temp2/=7;
	}

	// prnt(x+y);

	// prnt(power(7,x-1));

	// prnt(to7(n));

	if((power(7,x-1))==(n)) x--;
	if((power(7,y-1))==(m)) y--;

	// cout<<x<<" "<<y<<endl;

	if(x==0) x=1; if(y==0) y=1;

	if(x+y>7) prnt(0);
	else
	{
		go1(-1,0,x,"");
		go2(-1,0,y,"");

		int ans=0;

		FOR(i,0,h.size())
		{
			FOR(j,0,mn.size())
			{
				if(check(h[i],mn[j]))
				{
					// cout<<h[i]<<" "<<mn[j]<<endl;
					ans++;
				}
			}
		}

		prnt(ans);
	}

	// FOR(i,0,h.size()) cout<<h[i]<<" "; cout<<endl;
	// FOR(i,0,mn.size()) cout<<mn[i]<<" "; cout<<endl;

	return 0;
}

#include <stdio.h>
#include <string.h>

#define lli long long int

lli digitn[15], digitm[15], lenm = 0, memo1[15][260][5], memo2[15][260][5];

lli dp2(lli pos2, lli mask2, lli kode2) {
	lli ret2 = 0;
	if (pos2 < 1)
		return 1;
	if (memo2[pos2][mask2][kode2] != -1)
		return memo2[pos2][mask2][kode2];
	for (int i = 0; i < 7; i++) {
		if (mask2 & (1 << i))
			continue;
		if (i < digitm[pos2])
			ret2 += dp2(pos2 - 1, mask2 | (1 << i), 0);
		else if (i == digitm[pos2])
			ret2 += dp2(pos2 - 1, mask2 | (1 << i), kode2);
		else if (kode2 < 1)
			ret2 += dp2(pos2 - 1, mask2 | (1 << i), 0);
	}
	memo2[pos2][mask2][kode2] = ret2;
	return ret2;
}

lli dp1(lli pos1, lli mask1, lli kode1) {
	lli ret1 = 0;
	if (pos1 < 1)
		return dp2(lenm, mask1, 1);
	if (memo1[pos1][mask1][kode1] != -1)
		return memo1[pos1][mask1][kode1];
	for (int i = 0; i < 7; i++) {
		if (mask1 & (1 << i))
			continue;
		if (i < digitn[pos1])
			ret1 += dp1(pos1 - 1, mask1 | (1 << i), 0);
		else if (i == digitn[pos1])
			ret1 += dp1(pos1 - 1, mask1 | (1 << i), kode1);
		else if (kode1 < 1)
			ret1 += dp1(pos1 - 1, mask1 | (1 << i), 0);
	}
	memo1[pos1][mask1][kode1] = ret1;
	return ret1;
}

int main() {
	lli n, m, lenn = 0, ans;
	scanf("%lld %lld", &n, &m);
	n--;
	m--;
	if (n < 1)
		digitn[++lenn] = 0;
	while (n > 0) {
		digitn[++lenn] = n % 7;
		n /= 7;
	}
	if (m < 1)
		digitm[++lenm] = 0;
	while (m > 0) {
		digitm[++lenm] = m % 7;
		m /= 7;
	}
	memset(memo1, -1, sizeof memo1);
	memset(memo2, -1, sizeof memo2);
	ans = dp1(lenn, 0, 1);
	printf("%lld\n", ans);
}

#include "cstdio"
#include "iostream"
#include "algorithm"
#include "string"
#include "cstring"
#include "queue"
#include "cmath"
#include "vector"
#include "map"
#include "stdlib.h"
#include "set"
#define mj
#define db double
#define ll long long
using  namespace std;
const int N=2e5+5;
const int mod=1e9+7;
const ll inf=1e16+10;
int a[8];
int ans=0;
void cal(int x,int y,int n,int m){
    for(int i=0;i<7;i++) a[i]=0;
    if(!n) a[0]++;
    if(!m) a[0]++;
    while (n){
        a[x%7]++;
        x/=7;
        n/=7;
    }
    while (m){
        a[y%7]++;
        y/=7;
        m/=7;
    }
    for(int i=0;i<7;i++)
        if(a[i]>1) return;
    ans++;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(1ll*n*m>1e7){
        puts("0");
    }
    else {
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cal(i,j,n-1,m-1);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

#include <stdio.h>
#include <vector>
#include <string>
using namespace std;

int n, m;
vector<int> left(256, 0);
vector<int> right(256, 0);

string num2str(int i){
	if(i == 0) return "0";
	string s = "";
	while(i != 0){
		s = (char)(i % 7 + '0') + s;
		i /= 7;
	}
	return s;
}

bool valid(int i, int bitnum){
	string s = num2str(i);
	if(s.length() < bitnum - 1) return false;

	int num[7] = {0};
	if(s.length() == bitnum - 1) num[0]++;

	for(int i = 0; i < s.length(); i++){
		num[s[i]-'0']++;
	}
	for(int i = 0; i < 7; i++){
		if(num[i] > 1)
			return false;
	}
	return true;
}

int computeIdx(int i, int bitnum){
	int idx = 0;
	string s = num2str(i);
	int num[7] = {0};
	if(s.length() == bitnum - 1) num[0]++;
	for(int i = 0; i < s.length(); i++){
		num[s[i]-'0']++;
	}
	for(int i = 0; i < 7; i++){//numbit
		if(num[i] != 0)
			idx |= (1 << i);
	}
	return idx;
}

void countValid(vector<int>& v, int n){

	int bitnum = 0;
	if(n == 1)
		bitnum = 1;
	else{
		int tmp = n - 1;
		while(tmp != 0){
			bitnum++;
			tmp /= 7;
		}
	}

	if(bitnum > 7) return;

	for(int i = 0; i < 823543; i++){
		if(i >= n) break;
		if(valid(i, bitnum)){
			int idx = computeIdx(i, bitnum);
			v[idx]++;
			//printf("i=%d, idx=%d, v[idx]=%d\n", i, idx, v[idx]);
		}
	}
}

int match(){
	int cnt = 0;
	for(int i = 1; i < left.size(); i++){
		for(int j = 1; j < right.size(); j++){
			if((i&j) == 0){
				cnt += left[i] * right[j];
			}
		}
	}
	return cnt;
}

int main(){
	scanf("%d %d", &n, &m);

	countValid(left, n);

	countValid(right, m);

	printf("%d\n", match());

	return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;

int n, m;
bool used[7];
int counter = 0, digitn = 0, digitm = 0;

bool checkh(int x)
{
	if (x >= 0 && x < n)
		return true;
	return false;
}

bool checkm(int x)
{
	if (x >= 0 && x < m)
		return true;
	return false;
}

void permutem(int a, int number)
{
	if (number == digitm)
	{
		if (checkm(a))
			counter++;
		return;
	}

	for (int i = 0; i < 7; i++)
		if (!used[i])
		{
			used[i] = true;
			permutem(a * 7 + i, number + 1);
			used[i] = false;
		}
}

void permuteh(int a, int number)
{
	if (number == digitn)
	{
		if (checkh(a))
			permutem(0, 0);
		return;
	}

	for (int i = 0; i < 7; i++)
			if (!used[i])
			{
				used[i] = true;
				permuteh(a * 7 + i, number + 1);
				used[i] = false;
			}
}

int main()
{
	cin >> n >> m;

	int faken = n - 1, fakem = m - 1;
	if (n == 1)
		faken = 1;
	if (m == 1)
		fakem = 1;

	while (faken > 0)
	{
		faken /= 7;
		digitn++;
	}
	while (fakem > 0)
	{
		fakem /= 7;
		digitm++;
	}
	if (digitn + digitm > 7)
		cout << 0 << "\n";
	else
	{
		permuteh(0, 0);
		cout << counter << "\n";
	}

	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cmath>
#include<set>
#include<vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
const int N = (int)1e5 + 113;

long long n, m, x, y, ans;
bool used[7];
long long func(long long val) {
	if (val < 7) {
		return 1;
	}

	return 1 + func(val / 7);
}

void per(vector <long long> dec, long long nn, long long mm, long long num) {
	if (num == (x + y)) {
		if (mm >= m)
			return;

		memset(used, 0, sizeof(used));
		for (int i = 0; i < dec.size(); i++) {
			if (used[dec[i]])
				return;
			used[dec[i]] = 1;
		}
		ans++;
		return;
	}

	if (num == x) {
		if (nn >= n)
			return;
	}

	for (long long i = 0; i < 7; i++) {
		vector <long long> newDec = dec;
		newDec.push_back(i);
		if (num < x) {
			per(newDec, nn * 7 + i, mm, num + 1);
		}
		else{
			per(newDec, nn, mm * 7 + i, num + 1);
		}
	}
}
int main(){
	//freopen("input.txt", "r", stdin);

	cin >> n >> m;

	x = func(n - 1);
	y = func(m - 1);
	if (x + y > 7) {
		cout << 0;
		return 0;
	}

	vector <long long> toPerebor;
	per(toPerebor, 0, 0, 0);
	cout << ans;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define f(a,b,c) for(int a=b;a<c;a++)
#define dbg if(0)
#define dbg2 if(0)
typedef long long int lli;
int digits(int n){
	int c=0;
	if(n==0)return 1;
	while(n>0){
		c++;
		n/=7;
	}
	return c;
}
int dg1,dg2,tester,tester2,mkd[7];
bool can(int n,int m){
	memset(mkd,0,sizeof mkd);
	f(i,0,dg1){
		if(mkd[n%7])return false;
		mkd[n%7]=1;
		n=n/7;
	}
	f(i,0,dg2){
		if(mkd[m%7])return false;
		mkd[m%7]=1;
		m=m/7;
	}
	return true;
}
int solve(int n,int m){
	int w=0;
	f(i,0,n)f(j,0,m){
		dbg cout<<i<<" @ "<<j;
		if(can(i,j)){w++;dbg cout<<"OK";}
		dbg cout<<endl;
	}return w;
}
int main(){
	int n,m;
	cin>>n>>m;
	assert(n>0&&m>0);
		dg1=digits(n-1);
		dg2=digits(m-1);
		if(dg1+dg2<=7)
		cout<<solve(n,m)<<endl;
		else cout<<0<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int N, M, NN, MM;
int n[20], m[20], t1, t2;
int B[20], T;
int ST[6000], S[6000], top;
void DFS(int id,int cur,int num){
    if(num >= NN) return;
    if(id > t1) {
	++top;
	S[top] = cur; ST[top] = num;
    }
    else {
	for(int i = 0;i < 7; ++i){
	    if((cur & (1 << i)) == 0)
		DFS(id + 1, cur | (1 << i), num * 7 + i);
	}
    }
}

int ST1[6000], S1[6000], top1;
void DFS1(int id,int cur,int num){
    if(num >= MM) return;
    if(id > t2) {
	++top1;
	S1[top1] = cur; ST1[top1] = num;
    }
    else {
	for(int i = 0;i < 7; ++i){
	    if((cur & (1 << i)) == 0)
		DFS1(id + 1, cur | (1 << i), num * 7 + i);
	}
    }
}

int main(){
    if(fopen("input.txt","r")){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    }

    scanf("%d%d", &N, &M); NN = N; MM = M;
    N--; M--;
    while(N) { n[++t1] = N % 7; N /= 7; }
    while(M) { m[++t2] = M % 7; M /= 7; }
    for(int i = 1;i <= t1 / 2; ++i) swap(n[i], n[t1 + 1 - i]);
    for(int i = 1;i <= t2 / 2; ++i) swap(n[i], n[t2 + 1 - i]);

    if(t1 == 0) t1 = 1;
    if(t2 == 0) t2 = 1;
    if(t1 + t2 > 7) puts("0");
    else {
	DFS(1, 0, 0);
	DFS1(1, 0, 0);
	int ans = 0;
	for(int i = 1;i <= top; ++i){
	    for(int j = 1;j <= top1; ++j){
		if((S[i] & S1[j]) == 0){
		    ans++;
		}
	    }
	}
	printf("%d", ans);
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define int long long
typedef pair<int,int> pii;

const int mod = 1e9 + 7;
const int MOD = 998244353;
const int N = 5e5 + 5;

int lena , lenb;
int rem[8] , vis[8];
int n , m;
int fun(int ind){
    if(ind == lena + lenb){
        int a = 0 , b = 0;
        for(int i = 0 ;i < lena; i++){
            a = a * 7 + rem[i];
        }
        for(int i = lena ; i < lena + lenb ; i ++){
            b = b * 7 + rem[i];
        }
        // cout << "hey" << endl;
        return (a < n && b < m)?1:0;
    }

    int res = 0;
    for(int i = 0; i < 7 ; i ++){
        if(vis[i]) continue;
        rem[ind] = i;
        vis[i] = 1;
        res += fun(ind + 1);
        vis[i] = 0;
    }
    return res;
}

void solve(){
    cin >> n >> m;
    for(int i = 7 ; i < n ; i *= 7){
        lena ++;
    }
    for(int i = 7 ; i < m ; i *= 7){
        lenb ++;
    }
    lena++; lenb++;
    if(lena + lenb > 7){
        cout << 0 << endl;
        return;
    }
    // cout << "lena : " << lena << " lenb : " << lenb << endl;
    memset(rem , 0 , sizeof(rem));
    memset(vis , 0 , sizeof(vis));
    cout << fun(0) << endl;
}

int32_t main(){
    // ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    // cin >> t;
    for(int T = 1 ; T <= t ; T++){
        // cout << "Case #" << T << ": " << endl;
        solve();
    }
}

# include<stdio.h>
# include<string.h>
# include<vector>
# include<algorithm>
using namespace std;

int n,m;
int seven[10];
int num_n,num_m;
bool vis[11];
int ans=0;
int a[11];

void dfs(int cur){
    if(cur>num_n+num_m){
        int first=0,second=0;
        for(int i=1;i<=num_n;i++) first=first*7+a[i];
        for(int i=num_n+1;i<=num_n+num_m;i++) second=second*7+a[i];
        if(first<=n&&second<=m) {ans++;//printf("first:%d second:%d\n",first,second);
        }
        return;
    }

    for(int i=0;i<7;i++){
        if(vis[i]) continue;
        a[cur]=i;vis[i]=1;
        dfs(cur+1);
        vis[i]=0;
    }
}

int main(){
    seven[0]=1;
    for(int i=1;i<10;i++) seven[i]=seven[i-1]*7;
    scanf("%d%d",&n,&m);n--;m--;

    int nn=n,mm=m;
    num_n=num_m=0;
    while(nn>0) num_n++,nn/=7;
    while(mm>0) num_m++,mm/=7;

    if(n==0) num_n=1;if(m==0) num_m=1;

    if(num_n+num_m>7){
        puts("0");return 0;
    }

    memset(vis,0,sizeof(vis));ans=0;
    dfs(1);

    printf("%d\n",ans);
    return 0;
}

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

int calc(int x) {
	if (x == 1)return 1;
	x--;
	int res = 0;
	while (x > 0) {
		res++; x /= 7;
	}
	return res;
}
void solve() {
	int n, m; cin >> n >> m;
	int cn = calc(n), cm=(calc(m));
	if (cn + cm > 7) {
		cout << 0 << "\n"; return;
	}
	int ans = 0;
	vector<int> col;
	function<void(int, int)> dfs = [&](int num, int s) {
		if (num == cn + cm) {
			int cl = 0, cr = 0;
			rep(i, cn) {
				cl = cl * 7 + col[i];
			}
			rep(i, cm) {
				cr = cr * 7 + col[i+cn];
			}
			if (cl < n && cr < m)ans++;
			return;
		}
		rep(to, 7) {
			if (s & (1 << to))continue;
			col.push_back(to);
			dfs(num + 1, s ^ (1 << to));
			col.pop_back();
		}
	};
	dfs(0, 0);
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(15);
	//init_f();
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}

#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std;

typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=0x3f3f3f3f3f3f3f3f;
const int N=1000+7;
const int M=7;

int n,m,v[N],tot,num[2][1<<M];
char s[N];

void solve(int pos,int now,int op,bool limit)
{
    if(pos==-1)
    {
        num[op][now]++;
        return;
    }
    int up=limit? s[pos]-'0':6;

    for(int i=0;i<=up;i++)
    {
        if(now&(1<<i))
            continue;
        solve(pos-1,now|(1<<i),op,limit&&(i==up));
    }
}
void work(int n,int op)
{
    tot=0;
    if(n)
    {
        while(n)
        {
            s[tot++]='0'+(n%7);
            n/=7;
        }
    }
    else s[tot++]='0';
    s[tot]='\0';
    solve(tot-1,0,op,1);
}
int main()
{
    read(n);read(m);
    work(n-1,0);
    work(m-1,1);
    int up=1<<M;
    ll ans=0;

    for(int i=1;i<up;i++)
        for(int j=1;j<up;j++)
            if(!(i&j))
                ans+=1ll*num[0][i]*num[1][j];

    printf("%lld\n",ans);
    return 0;
}
/*
343 2401
*/

#include<vector>
#include<iostream>
#include<stdio.h>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<cstdlib>
#include<ctime>
#include<cstring>
#include<climits>
#include<sstream>
#include<string.h>
#include<set>
#include<map>
#include<utility>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<bitset>

#define lli long long
#define mp make_pair
#define pi pair<int,int>
#define pli pair<lli,lli>
#define pb push_back
#define F first
#define S second

const double EPS = 1e-24;
const lli mod = 1000000007ll;
const double PI = 3.14159265359;
lli INF = 214748364542123113ll;

template <class T>T Max2(T a,T b){return a<b?b:a;}
template <class T>T Min2(T a,T b){return a<b?a:b;}
template <class T>T Max3(T a,T b,T c){return Max2(Max2(a,b),c);}
template <class T>T Min3(T a,T b,T c){return Min2(Min2(a,b),c);}
template <class T>T Max4(T a,T b,T c,T d){return Max2(Max2(a,b),Max2(c,d));}
template <class T>T Min4(T a,T b,T c,T d){return Min2(Min2(a,b),Max2(c,d));}

using namespace std;

int gcd(int a , int b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
}

vector<int> nrep;
vector<int> mrep;
int dign,digm;
int num(lli n)
{
    lli b = 7;
    int ans = 1;
    while(n/b>0)
    {
        b = b*7;
        ans++;
    }
    return ans;
}
int ans = 0;
void recur(int vis[], int i, bool tc)
{
    if(i>dign+digm)
    {
        //cout<<"here"<<i<<endl;
        ans++;
        return;
    }
    if(i==1)
    {
        for(int j=0;j<nrep[0];j++)
        {
            //cout<<i<<" "<<j<<endl;
            vis[j] = 1;
            recur(vis,i+1,false);
            vis[j] = 0;
        }
        vis[nrep[0]] = 1;
        recur(vis,i+1,true);
        vis[nrep[0]] = 0;
    }
    else if(i<=dign)
    {
        if(tc == false)
        {
            for(int j=0;j<7;j++)
            {
                if(!vis[j])
                {
                    //cout<<i<<" "<<j<<endl;
                    vis[j] = 1;
                    recur(vis,i+1,false);
                    vis[j] = 0;
                }
            }
        }
        else
        {
            for(int j=0;j<nrep[i-1];j++)
            {
                if(!vis[j])
                {
                    //cout<<i<<" "<<j<<endl;
                    vis[j] = 1;
                    recur(vis,i+1,false);
                    vis[j] = 0;
                }
            }
            if(!vis[nrep[i-1]])
            {
                //cout<<i<<" "<<nrep[i-1]<<endl;
                vis[nrep[i-1]] = 1;
                recur(vis,i+1,true);
                vis[nrep[i-1]] = 0;
            }
        }
    }
    else if(i == dign+1)
    {
        for(int j=0;j<mrep[0];j++)
        {
            if(!vis[j])
            {
                //cout<<i<<" "<<j<<endl;
                vis[j] = 1;
                recur(vis,i+1,false);
                vis[j] = 0;
            }
        }
        if(!vis[mrep[0]])
        {
            //cout<<i<<" "<<mrep[0]<<endl;
            vis[mrep[0]] = 1;
            recur(vis,i+1,true);
            vis[mrep[0]] = 0;
        }
    }
    else
    {
        int k = i-dign;
        if(tc == false)
        {
            for(int j=0;j<7;j++)
            {
                if(!vis[j])
                {
                    //cout<<i<<" "<<j<<endl;
                    vis[j] = 1;
                    recur(vis,i+1,false);
                    vis[j] = 0;
                }
            }
        }
        else
        {
            for(int j=0;j<mrep[k-1];j++)
            {
                if(!vis[j])
                {
                    //cout<<i<<" "<<j<<endl;
                    vis[j] = 1;
                    recur(vis,i+1,false);
                    vis[j] = 0;
                }
            }
            if(!vis[mrep[k-1]])
            {
                //cout<<i<<" "<<mrep[k-1]<<endl;
                vis[mrep[k-1]] = 1;
                recur(vis,i+1,true);
                vis[mrep[k-1]] = 0;
            }
        }
    }
}
int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);

    lli n,m;
    cin>>n>>m;

    dign = num(n-1);
    digm = num(m-1);
    if(dign+digm>7)
    {
        cout<<0<<endl;
        return 0;
    }
    lli n1 = n-1,m1=m-1;
    if(n1 == 0)
        nrep.pb(0);
    if(m1 == 0)
        mrep.pb(0);
    while(n1>0)
    {
        nrep.pb(n1%7);
        n1/=7;
    }
    reverse(nrep.begin(),nrep.end());
    while(m1>0)
    {
        mrep.pb(m1%7);
        m1/=7;
    }
    reverse(mrep.begin(),mrep.end());

    int vis[8];
    for(int i=0;i<8;i++)
    {
        vis[i] = 0;
    }
    //cout<<dign<<" "<<digm<<endl;
    /*for(int i=0;i<nrep.size();i++)
        cout<<nrep[i]<<" ";
    cout<<endl;*/
    recur(vis,1,false);
    cout<<ans<<endl;

	return 0;
}

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
 * Created By : Aditya Agarwal
 * IT, MNNIT-ALLAHABAD
 * aditya.mnnit15@gmail.com
 _._._._._._._._._._._._._._._._._._._._._.*/

#include<bits/stdc++.h>
using namespace std;

#define MP make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=b;i>=a;i--)
#define X first
#define Y second

 //i/o
#define inp(n) scanf("%d",&n)
#define inpl(n) scanf("%lld",&n)
#define inp2(n,m) inp(n), inp(m)
#define inp2l(n,m) inpl(n), inpl(m)

//cost
#define MOD 1000000007
#define MOD_INV 1000000006
#define MAX 100009
#define INF 999999999
#define mp make_pair
typedef long long ll;
typedef pair< pair<ll,ll>,ll > pairs;

int main(){
	ll a,b;
	inp2l(a,b);
	int nd=0,md=0,t;
	a--;
	b--;
	t=a;
	while(t){
		nd++;
		t/=7;
	}
	t=b;
	while(t){
		md++;
		t/=7;
	}
	if(a==0)
		nd=1;
	if(b==0)
		md=1;
	if(nd+md>7){
		cout<<0<<endl;
		return 0;
	}
	int r[nd+md+1];
	ll ans=0;
	rep(i,7){
		r[0]=i;
		rep(j,7){
			r[1]=j;
			if(nd+md==2 && j!=i){
				int x=0,y=0;
				PER(j,0,nd-1){
					x+=(r[j]*pow(7,nd-1-j));
				}
				PER(j,nd,nd+md-1){
					y+=(r[j]*pow(7,nd+md-1-j));
				}
				if(x<=a && y<=b){
					ans++;
					}
				}
			else
				rep(k,7){
					r[2]=k;
					if(nd+md==3 && j!=i && k!=i && k!=j){
					int x=0,y=0;
					PER(j,0,nd-1){
						x+=(r[j]*pow(7,nd-1-j));
					}
					PER(j,nd,nd+md-1){
						y+=(r[j]*pow(7,nd+md-1-j));
					}
					if(x<=a && y<=b){
						ans++;
						}
					}
					else
						rep(l,7){
							r[3]=l;
							if(nd+md==4 && j!=i && k!=i && k!=j && l!=i && l!=j && l!=k){
							int x=0,y=0;
							PER(j,0,nd-1){
								x+=(r[j]*pow(7,nd-1-j));
							}
							PER(j,nd,nd+md-1){
								y+=(r[j]*pow(7,nd+md-1-j));
							}
							if(x<=a && y<=b){
								ans++;
								}
							}
							else
								rep(m,7){
									r[4]=m;
									if(nd+md==5 && j!=i && k!=i && k!=j
										&& l!=i && l!=j && l!=k && m!=i
										&& m!=j && m!=k && m!=l){
									int x=0,y=0;
									PER(j,0,nd-1){
										x+=(r[j]*pow(7,nd-1-j));
									}
									PER(j,nd,nd+md-1){
										y+=(r[j]*pow(7,nd+md-1-j));
									}
									if(x<=a && y<=b){
										ans++;
										}
									}
									else
										rep(n,7){
											r[5]=n;
											if(nd+md==6 && j!=i && k!=i &&
												k!=j && l!=i && l!=j && l!=k
												&& m!=i && m!=j && m!=k && m!=l
												&& n!=i && n!=j && n!=k && n!=l && n!=m){
											int x=0,y=0;
											PER(j,0,nd-1){
												x+=(r[j]*pow(7,nd-1-j));
											}
											PER(j,nd,nd+md-1){
												y+=(r[j]*pow(7,nd+md-1-j));
											}
											if(x<=a && y<=b){
												ans++;
												}
											}
											else
												rep(o,7){
													r[6]=o;
													if(nd+md==7 && j!=i && k!=i
														&& k!=j && l!=i && l!=j
														&& l!=k && m!=i && m!=j
														&& m!=k && m!=l && n!=i
														&& n!=j && n!=k && n!=l
														&& n!=m && o!=i && o!=j
														&& o!=k && o!=l && o!=m && o!=n){
													int x=0,y=0;
													PER(j,0,nd-1){
														x+=(r[j]*pow(7,nd-1-j));
													}
													PER(j,nd,nd+md-1){
														y+=(r[j]*pow(7,nd+md-1-j));
													}
													if(x<=a && y<=b){
														ans++;
														}
													}
												}
										}
								}
						}
				}
		}
	}
	cout<<ans<<endl;
	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;

	int hour, minute, x = 1, y = 1, p = 7, q = 7;

	while (p < n)
	{
		x++;
		p *= 7;
	}

	while (q < m)
	{
		y++;
		q *= 7;
	}

	if (x + y > 7)
	{
		cout << 0;
	}
	else
	{
		int ans = 0;
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < m; ++j)
			{
				vector<int> used(7, 0);
				for (int k = i, a = 0; a < x; k /= 7, ++a)
					used[k % 7]++;

				for (int k = j, a = 0; a < y; k /= 7, ++a)
					used[k % 7]++;
				if (*std::max_element(used.begin(), used.end()) <= 1)
					ans++;
			}
		}
		cout << ans;
	}

	return 0;
}

/*
for (int i = 0; i < n; ++i)
{

}
*/

#include<bits/stdc++.h>
using namespace std;
int result;
int h_b;
int m_b;
void check(int a, int b) {
    int num[10];
    memset(num, 0, sizeof(num));
    int bits = 0;
    while(a!=0) {
        num[a%7]++;
        a/=7;
        bits++;
    }
    while(b!=0) {
        num[b%7]++;
        b/=7;
        bits++;
    }
    if(bits < h_b+m_b) {
        num[0]+=(h_b+m_b-bits);
    }
    for(int i = 0; i < 10; i++) {
        if(num[i]>1) return;
    }
    result++;

}
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    result = 0;
    h_b = 0;
    m_b = 0;

    int n1 = n-1;
    while(n1!=0) {
        h_b++;
        n1/=7;
    }

    int m1 = m-1;
    while(m1!=0) {
        m_b++;
        m1/=7;
    }
//    printf("%d", h_b+m_b);
    if(h_b == 0) h_b=1;
    if(m_b == 0) m_b=1;
    if(h_b+m_b<=7) {
        int i, j;
        for(i = 0; i < n; i++) {
            for(j = 0; j < m; j++) {
                check(i,j);
            }
        }
    } else {
//        printf(",");
        result = 0;
    }
    printf("%d\n", result);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<ll,ll> pl;

#define sl(x) scanf("%lld",&x)
#define pl(x) printf("%lld\n",x)
#define sf(x) sort(x.begin(),x.end(),func)
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

const ll mod = 1000000007;
const ll inf = 1e16;
const ll ninf = LLONG_MIN;
const ld eps = 1e-12;
const ll N = 1000005;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
ll n, m;
ll rn, rm;
ll p[102];
ll x[102], y[102];
ll dp[10][1 << 6 + 4][2];
ll solve(ll i, ll mask, ll iseq)
{
    if(i == m + n)
    {
        return 1;
    }
    if(dp[i][mask][iseq] != -1) return dp[i][mask][iseq];
    ll ans = 0;
    for(ll j = 0; j <= 6; j++)
    {
        if(mask & p[j]) continue;
        if(iseq)
        {
            if(i < n)
            {
                if(x[i] < j)
                {
                    break;
                }
                else if(x[i] == j)
                {

                    ans += solve(i + 1, mask | (p[j]), 1);

                }
                else
                {

                    if(i == n - 1) ans += solve(i + 1, mask | (p[j]), 1);
                    else ans += solve(i + 1, mask | (p[j]), 0);
                }
            }
            else
            {

                if(y[i - n] < j)
                {
                    break;
                }
                else if(y[i - n] == j)
                {

                    ans += solve(i + 1, mask | (p[j]), 1);

                }
                else
                {

                    ans += solve(i + 1, mask | (p[j]), 0);

                }
            }
        }
        else
        {

            if(i == n - 1)
                ans += solve(i + 1, mask | p[j], 1);
            else
                ans += solve(i + 1, mask | (p[j]), 0);

        }
    }
    dp[i][mask][iseq] = ans;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    memset(dp, -1, sizeof(dp));
    n--;
    m--;
    p[0] = 1;
    for(ll i = 1; i <= 8; i++) p[i] = p[i - 1] * 2;
    ll nn = n, mm = m;
    ll k = 0;
    while(nn)
    {
        x[k++] = nn % 7;
        nn /= 7;
    }
    reverse(x, x + k);
    rn = k;
    if(n == 0)
    {
        rn = 1;
        x[0] = 0;
    }
    n = rn;
    k = 0;
    while(mm)
    {
        y[k++] = mm % 7;
        mm /= 7;
    }
    reverse(y, y + k);
    rm = k;
    if(m == 0)
    {
        rm = 1;
        y[0] = 0;
    }
    m = rm;
    cout << solve(0, 0, 1) << "\n";
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define PI 2*asin(1)
#define all(v) v.begin(),v.end()
#define forall(it,v) for(it=v.begin();it!=v.end();it++)
#define clr(v,n) memset(v,n,sizeof v)
#define REP(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b) for(int i=a; i<b; i++)
#define sz(v) (int)v.size()
#define pii pair<int,int>
#define F first
#define S second
#define INF INT_MAX
#define EPS 1e-7
inline ll gcd (ll a, ll b) { return (b?gcd(b, a%b):a); }
inline ll lcm (ll a, ll b) { return (a/gcd(a, b))*b; }
inline int cmp(double x, double y = 0, double tol = EPS){return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;}
using namespace std;
const int MAXN=100005;

int qtd(ll x){
	if(x==0) return 1;

	int cont=0;
	while(x){
		cont++;
		x/=7;
	}
	return cont;
}

ll v[8], QA, QB;

bool ok(ll a, ll b){
	clr(v,0);

	for(int i=0; i<QA; i++){
		v[a%7]++;
		a/=7;
	}

	for(int i=0; i<QB; i++){
		v[b%7]++;
		b/=7;
	}

	for(int i=0; i<8; i++)
		if(v[i]>=2) return false;
	return true;
}

int main(){
	ll a, b;
	cin >> a >> b;

	QA= qtd(a-1);
	QB= qtd(b-1);
	//cout << QA << " " << QB << endl;
	if(QA+QB>=9){
		cout << 0 << endl;
	}
	else{
		ll ans=0;

		for(ll i=0; i<a; i++){
			for(ll j=0; j<b; j++){
				if(ok(i,j)){
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

#include <iostream>
using namespace std;
long long degree(int basis, int value)
{
		int i;
		long long ans = 1;
		for(i = 1; i <= value; i++)
		{
			ans = ans*basis;
		}
		return(ans);
}
long long toseven(long long x)
{
		 int k = 0;
		long long ans = 0;
 	while (x > 0)
		{
			ans = ans + (x % 7)*degree(10, k);
			x = x / 7;
			k = k + 1;
		}
		return(ans);
}
int getsize(long long x)
{
		int ans = 0;
		if (x > 0) {
		while (x > 0)
		{
			x = x / 10;
			ans = ans + 1;
		}}
		else
		{
		    ans = 1;
		}
		return(ans);
}
int main()
{
	long long n, m;
cin >> n >> m;
n = n - 1;
m = m - 1;
int kn = getsize(toseven(n));
int km = getsize(toseven(m));
int ans = 0;
if (kn + km > 7)
{
		ans = 0;
}
else
{
bool checkN[7], checkM[7], fl, flm;
int h, min, x, y, i;
for(h = 0; h <= n; h++)
{
for(i = 0; i <= 6; i++)
{
	checkN[i] = false;
}
fl = true;
x = toseven(h);
for (i = 1; i <= kn; i++)
{
	y = x % 10;
	if (checkN[y] == false)
	{
		checkN[y] = true;
	}
	else
	{
		fl = false;
		break;
	}
	x = x / 10;
}
if (fl == true)
{
	for(min = 0; min <= m; min++ )
	{
		for(i = 0; i <= 6; i++)
{
	checkM[i] = false;
}
flm = true;
x = toseven(min);
for (i = 1; i <= km; i++)
{
	y = x % 10;
	if ((checkN[y] == false) && (checkM[y] == false))
	{
		checkM[y] = true;
	}
	else
	{
		flm = false;
		break;
	}
	x = x / 10;
}
		if (flm == true)
		{
		ans = ans + 1;
		}
	}
}
}
}
cout << ans;
return(0);
}

#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
using namespace std;

typedef long long ll;
typedef pair< int, int > PII;
typedef pair< ll, ll > PLL;

#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define PI 3.14159265358979323846
#define INF 1000000006
#define LINF 1000000000000000006
#define FI first
#define SE second
#define PB push_back
#define MP make_pair

const int N = 100010;
ll n, m;
ll a[ 10 ];
ll d1, d2;
ll ans = 0;

void init() {
  cin >> n >> m;
}
ll cd( ll a ) {
  ll temp = a, t = 0;
  if ( a % 7 == 0 ) {
    while ( temp > 1 ) {
      temp /= 7;
      ++t;
    }
    return t;
  }
  while ( temp > 0 ) {
    temp /= 7;
    ++t;
  }
  return t;
}
bool check2( ll b1, ll b2, ll c ) {
  ll temp = 0, d = 1;
  for ( int i = b1 ; i < b2 ; ++i ) {
    temp += d * a[ i ];
    d *= 7;
  }
  return ( temp < c );
}
bool check() {
  bool b[ 20 ] = { false };
  for ( int i = 0 ; i < d1 + d2 ; ++i ) {
    if ( b[ a[ i ] ] == true )
      return false;
    else
      b[ a[ i ] ] = true;
  }
  if ( check2( 0, d2, m ) && check2( d2, d1 + d2, n ) ) {
/*
    for ( int i = d1 + d2 - 1 ; i >= d2 ; --i )
      cout << a[ i ];
    cout << " ";
    for ( int i = d2 - 1 ; i >= 0 ; --i )
      cout << a[ i ];
    cout << endl;
*/
    return true;
  }
  return false;
}
void cal( ll index ) {
  if ( index == ( d1 + d2 ) ) {
    if ( check() )
      ++ans;
    return;
  }
  for ( int i = 0 ; i < 7 ; ++i ) {
    a[ index ] = i;
    cal( index + 1 );
  }
}
int main() {
  IOS;
  init();

  d1 = cd( n ); d2 = cd( m );
  if ( d1 + d2 > 7 ) {
    cout << "0" << endl;
    return 0;
  }

  cal( 0 );

  cout << ans << endl;
}

#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
    if(y==0)
        return x;
    else
        return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
        if(m%2)
            r=(r*n)%p;
        n=(n*n)%p;
        m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}
int ans=0,n,m;
int ta=0,tb=0;
void solve(int N,int M,int a,int b,bool vis[])
{
	if(a==0&&b==0)
	{
		//cout<<"Ko";
		if(N<=ta&&M<=tb){
			//cout<<N<<' '<<M<<endl;
			ans++;
		}
		return ;
	}
	//debug3(a,b,N);
	bool t[10];
	for(int i=0;i<10;i++)
	{
		t[i]=vis[i];
	}
	if(a!=0)
	{
		for(int i=0;i<7;i++)
		{
			if(!t[i])
			{
				t[i]=true;
				N=N*10+i;
				solve(N,M,a-1,b,t);
				t[i]=false;
				N=N/10;
			}
		}
	}
	else
	{
		for(int i=0;i<7;i++)
		{
			if(!t[i])
			{
				t[i]=true;
				M=M*10+i;
				solve(N,M,a,b-1,t);
				t[i]=false;
				M=M/10;
			}
		}
	}
}
int32_t main()
{
   IOS;
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/
   cin>>n>>m;
   int a=0,b=0;
   int N=n,M=m;
   if(n==1&&m==1)
   {
   	cout<<0<<endl;
   	return 0;
   }
   n--,m--;
   while(n)
   {
   	a++;
   	n=n/7;
   }
   while(m)
   {
   	b++;
   	m=m/7;
   }
  // cout<<a+b<<endl;
   if(a+b>8)
   {
   	cout<<0<<endl;
   	return 0;
   }
   n++,m++;
   n=N,m=M;
   bool vis[10];
   memset(vis,false,sizeof(vis));
   //int ta=0,tb=0;
   N--,M--;
   string A,B;
   while(N)
   {
   	A.pb('0'+N%7);
   	N=N/7;
   }
   if(A.size()>0)
   reverse(all(A));
  // cout<<A<<endl;
   if(A.size()>0)
   ta=stoi(A);
   A.clear();
   while(M)
   {
   	A.pb('0'+M%7);
   	M=M/7;
   }
   if(A.size())
   reverse(all(A));
  // cout<<A<<endl;
	if(A.size())
   	tb=stoi(A);
   if(ta==0||tb==0)
   	vis[0]=true;
   solve(0,0,a,b,vis);
   cout<<ans<<endl;
}

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <exception>
#include <numeric>
#include <algorithm>

using namespace std;

typedef long long lo;
typedef vector< vector<long long> > vvl;
typedef vector< long long> vl;
typedef pair<lo, lo> ll;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef pair<long, pair<long, long>> lll;
typedef vector<lll> vlll;
typedef vector<vvl> vvvl;
typedef vector<set<lo>> vs;
typedef map<lo, map<lo, lo>> mm;

lo dn, dm, p[10], ans=0, n, m;

lo log7(lo x) {
	if (x<7) return 0;
	return 1+ log7(x/7);
}
void f(lo pos) {
	if (pos==dm+dn) {
		lo val=0;
		for (lo i=0, mult=1;i<dn;i++, mult*=7)
			val+=p[i]*mult;
		if (val>=n) return;
		//cout<<val << " ";
		val=0;
		for (lo i=dn, mult=1;i<dn+dm;i++, mult*=7)
			val+=p[i]*mult;
		if (val>=m) return;
		ans++;
		//cout<<val<< "\n";

		return;
	}
	for (lo i=0;i<7;i++) {
		bool unused=true;
		for (lo j=0;j<pos && unused;j++)
			if (p[j]==i) unused=false;
		if (!unused) continue;
		p[pos]=i;
		f(pos+1);
	}
}
int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);

	cin >> n >> m;
	dn=log7(n-1)+1;
	dm=log7(m-1)+1;
//	cout<<dn << " " << dm;
	if (dn+dm<=7) f(0);

	cout<<ans;
	return 0;
}

#define HTzrNEnp false
#define GJtq true
#define Eujn  char
#define wHUS  int
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <string>
#include <string.h>
#include <iostream>
#include <queue>
using namespace std;
#define fi "input.txt"
#define fo "output.txt"
#define yoF freopen(fi,"r",stdin);freopen(fo,"w",stdout)
#define NwLu(i,l,r) for(wHUS i=(int)(l);i<=(int)(r);i++)
#define NwLuD(i,l,r) for(wHUS i=(int)(l);i>=(int)(r);i--)
#define FDS pair<double,double>
#define RztB long long
#define TzrNE first
#define FZwIA second
#define mvx push_back
#define CZdGT(a,v) memset(a,v,sizeof(a))
#define qqIqs(s) (int)(s.size())
#define EL printf("\n")
#define digit(x) ('0'<=x&&x<='9')
#define forever while (GJtq)
#define usi unsigned long long

const wHUS OO = (int) 2e9;
const wHUS MOD = (int) 1e9+7;
const long double Pi = 3.1415926535897932384626433832795;
const wHUS N = (int) 1e5+5;

wHUS n,m,a,b,ncSulI=0;
bool lpMfmk[7];

wHUS len(wHUS x)  {
    wHUS ncSulI=0;
    while (x>0) ncSulI++,x/=7;
    return max(1,ncSulI);
}

bool CPJFfs(wHUS x,wHUS y)  {
    //wHUS tmpa=x,tmmvx=y;
    CZdGT(lpMfmk,HTzrNEnp);
    NwLu(i,1,a)  {
        if (lpMfmk[x%7]) return HTzrNEnp;
        lpMfmk[x%7]=GJtq;x/=7;
    }
    NwLu(i,1,b)  {
        if (lpMfmk[y%7]) return HTzrNEnp;
        lpMfmk[y%7]=GJtq;y/=7;
    }
    return GJtq;
}

wHUS main()  {
    cin>>n>>m;
    a=len(n-1);
    b=len(m-1);
    if (a+b>7)  {cout<<0;return 0;}
    NwLu(i,0,n-1) NwLu(j,0,m-1)
        ncSulI+=CPJFfs(i,j);
    cout<<ncSulI;
}

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <limits>
#include <iomanip>
#include <ctime>
#include <map>
#include <queue>

using namespace std;

int mor;
vector<int> a(7);

struct numb {
	vector<int> c;
	int a;
	int lim;
};

void chan( int f, int t ) {
	a[f] -=1;
	if( a[f] == 1 ) {
		mor -=1;
	}
	a[t] +=1;
	if( a[t] == 2 ) {
		mor +=1;
	}
}

bool increment( numb& x) {
	if( x.a + 1 == x.lim ) {
		for( int i = 0; i < x.c.size(); i++ ) {
			chan(x.c[i],0);
			x.c[i] = 0;
		}
		x.a = 0;
		return true;
	} else {
		x.a +=1;
		int j = 0;
		while( x.c[j] == 6 && j < x.c.size() ) {
			chan(x.c[j],0);
			x.c[j] = 0;
			j++;
		}
		chan(x.c[j],x.c[j] + 1);
		x.c[j] +=1;
		return false;
	}
}

int main()  {
	int n,m; cin >> n >> m;
	int rn = int( log(double(n-1))/log(7.0) ) + 1;
	if( n == 1 )
		rn = 1;
	int rm = int( log(double(m-1))/log(7.0) ) + 1;
	if( m == 1 )
		rm = 1;
	if( rn + rm > 7 ) {
		cout << 0;
		return 0;
	}

	numb h;
	h.lim = n;
	h.a = 0;
	for( int v = 0; v < rn; v++ )
		h.c.push_back(0);
	numb min;
	min.lim = m;
	min.a = 0;
	for( int v = 0; v < rm; v++ )
		min.c.push_back(0);

	int ans = 0;
	int i = 1;
	mor = 1;
	a[0] = rn+rm;
	while( i != n*m ) {
		if( increment(min) ) {
			increment(h);
		}
		if( !mor ) {
			ans +=1;
		}
		i++;
	}
	cout << ans;
	return 0;
}

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::min;
using std::abs;
using std::max;

using std::sort;
using std::generate;
using std::min_element;
using std::max_element;

template <typename T>
T input() {
    T res;
    cin >> res;
    return res;
}

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    size_t n, m;
    cin >> n >> m;

    size_t len1 = 1, len2 = 1;
    for (size_t a = 7; a < n; a *= 7)
        len1 += 1;
    for (size_t b = 7; b < m; b *= 7)
        len2 += 1;

    size_t ans = 0;
    if (len1 + len2 <= 7)
        for (size_t i = 0; i != n; ++i)
            for (size_t j = 0; j != m; ++j) {
                vector<size_t> used(7, 0);

                for (size_t a = i, k = 0; k != len1; a /= 7, ++k)
                    used[a % 7] += 1;
                for (size_t b = j, k = 0; k != len2; b /= 7, ++k)
                    used[b % 7] += 1;

                if (*std::max_element(used.begin(), used.end()) <= 1)
                    ++ans;
            }

    cout << ans << "\n";

    return 0;
}

#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int ans = 0;

	int k1 = 1, k2 = 1;

	for (int i = 7; i < n; i *= 7)
        k1++;
    for (int i = 7; i < m; i *= 7)
        k2++;

	if(k1 + k2 > 7)
	{
		cout << 0 << endl;
		return 0;
	}

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			int a[7] = {0};

			int g = i, cn = 0;
			while(cn != k1)
			{
				a[g % 7]++;
				g /= 7;
				cn++;
			}

			cn = 0;
			g = j;
			while(cn != k2)
			{
				a[g % 7]++;
				g /= 7;
				cn++;
			}

			int f = 0;
            for(int i = 0; i < 7; i++)
			{
				if(a[i] > 1)
				{
					f = 1;
					break;
				}
			}
			if(!f)
				ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define pi 3.141592653589793238462643383279502884197169399375105820974944592307816406286

typedef long double ld;
typedef long long ll;	// Use "%I64d" as placeholder with printf and scanf.
typedef unsigned long long int ulli;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef priority_queue<ll, vector<ll>, greater<ll>> min_heap_ll;
typedef priority_queue<ll, vector<ll>, less<ll>> max_heap_ll;

#define f(i, n) for(ll i=0; i<n; ++i)
#define fi(i, n, j) for(ll i=j; i<n; ++i)
#define pb push_back
#define ins insert
#define mp make_pair
#define all(container) container.begin(), container.end()
#define allr(container) container.rbegin(), container.rend()
#define tr(container, it) for (decltype(container.begin()) it = container.begin(); it != container.end(); it++)
#define trr(container, it) for (decltype(container.rbegin()) it = container.rbegin(); it != container.rend(); it++)
#define cpresent(container, element) (container.find(element) != container.end())
#define present(container, element) (find(all(container),element) != container.end())
#define dist(a, b) sqrtl(powl(ld(a.first - b.first), 2) + powl(ld(a.second - b.second), 2))

#ifdef _CODE_SOURCE
double start_time, end_time;
#endif

// useful functions
void my_return(ll code)
{
#ifdef _CODE_SOURCE
	end_time = clock();
	printf("\nTime = %.3f seconds\n", (end_time - start_time) / CLOCKS_PER_SEC);
#endif
	exit(code);
}

ll gcd(ll a, ll b)
{
	return b ? gcd(b, a % b) : a;
}

ll my_exp(ll a, ll b)
{
	if (b == 0)
	{
		return 1;
	}
	else
	{
		ll temp = my_exp(a, b / 2);
		temp *= temp;
		if (b % 2 == 1)
		{
			temp *= a;
		}
		return temp;
	}
}

bool is_prime(ll n)	// O(sqrt(n)) implementation check for 0 and 1 separately
{
	if (n != 2 && n % 2 == 0)
	{
		return false;
	}
	else
	{
		for (int i = 3; (i*i) <= n; i += 2)
		{
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

// Program classes and structs

// Program functions
ll check(ll a, ll b, ll d1, ll d2)
{
	vll v;
	do {
		v.push_back(a % 7);
		a /= 7;
	} while (a != 0);
	while (v.size() != d1)
	{
		v.push_back(0);
	}
	do {
		v.push_back(b % 7);
		b /= 7;
	} while (b != 0);
	while (v.size() != d1 + d2)
	{
		v.push_back(0);
	}
	sort(all(v));
	fi(i, ll(v.size()), 1)
	{
		if (v[i - 1] == v[i])
		{
			return 0;
		}
	}
	return 1;
}

int main()
{
#ifdef _CODE_SOURCE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	start_time = clock();
#endif
	ios_base::sync_with_stdio(false);
	//Program Code
	ll n, m;
	cin >> n >> m;
	ll d1, d2;
	if (n - 1 != 0)
	{
		d1 = ll(logl(n - 1) / logl(7)) + 1;
	}
	else
	{
		d1 = 1;
	}
	if (m - 1 != 0)
	{
		d2 = ll(logl(m - 1) / logl(7)) + 1;
	}
	else
	{
		d2 = 1;
	}
	ll count = 0;
	if (d1 + d2 > 7)
	{
		cout << count;
	}
	else
	{
		f(i, n)
		{
			f(j, m)
			{
				count += check(i, j, d1, d2);
			}
		}
		cout << count;
	}

	my_return(0);
}

#include <bits/stdc++.h>
using namespace std;

int n, m, ln, lm, ans, vis[10];
string sn, sm;

string seven(int n) {
	string ans;
	for(; n > 0; n /= 7) {
		ans.push_back(n % 7);
	}
	reverse(ans.begin(), ans.end());
	return ans;
}

void dfs(int cur, int flag) {
	if(cur == ln + lm) {
		ans++;
		return;
	}
	int ub = 6;
	if(flag) {
		ub = cur < ln ? sn[cur] : sm[cur-ln];
	}
	for(int i = 0; i <= ub; i++) {
		if(!vis[i]) {
			int f = 1;
			if(cur != ln - 1) {
				f = flag && i == ub;
			}
			vis[i] = 1;
			dfs(cur + 1, f);
			vis[i] = 0;
		}
	}
}

int main() {
	cin >> n >> m;
	sn = seven(--n);
	sm = seven(--m);
	ln = max((int)sn.size(), 1);
	lm = max((int)sm.size(), 1);
	dfs(0, 1);
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define p 998244353
int binpow(int a , int b , int m)
{
	a=a%m;
	int res=1;
	while(b)
	{   if(b%2==1)
		res=(res*a)%m;
		a=(a*a)%m;
		b=b/2;
	}
	return res;
}

int32_t main() {

	int t=1;
	//cin >> t;
	while(t--)
	{
	   int n,m;
	   cin >> n >> m;

	   int x;

	   x = ((1.0*log2(n))/(1.0*log2(7)))+1;

	   int y = (1.0*log2(m))/log2(7)+1;
	    n--; m--;
	   if(x+y>7)cout << 0;
	   else
	   {  vector<int >v = {0,1,2,3,4,5,6};

	   	  set<pair<int , int >>s;
	   	  //set<vector<int>>ss;
	   	  int nn=0,mm=0,c=0;
	   	  for(int i=0; i<x; i++)
	   	  {
	   	  	nn=nn*7+v[i];
	   	  }
	   	  for(int i=x; i<x+y; i++)
	   	  {
	   	  	mm=mm*7+v[i];
	   	  }
	   	  if(nn<=n && mm<=m) s.insert({nn,mm});
	   	  while(next_permutation(v.begin(),v.end())){

	   	  nn=0,mm=0;
	   	 // ss.insert(v);

	   	  for(int i=0; i<x; i++)
	   	  {
	   	  	nn=nn*7+v[i];
	   	  }
	   	  for(int i=x; i<x+y; i++)
	   	  {
	   	  	mm=mm*7+v[i];
	   	  }
	   	  if(nn<=n && mm<=m) s.insert({nn,mm});
	   	  //c++;
	   	  } //int z=7-x-y;
	   	  cout << s.size();

	   }
	}
	// your code goes here
	return 0;
}

#define bzD false
#define Vjt true
#define IPp  char
#define BUEiu  int
#include    <stdio.h>
#include    <algorithm>
#include    <vector>
#include    <map>
#include    <set>
#include    <math.h>
#include    <string>
#include    <string.h>
#include    <iostream>
#include    <queue>
using    namespace    std;
#define    fi    "input.txt"
#define    fo    "output.txt"
#define    fFF    freopen(fi,"r",stdin);freopen(fo,"w",stdout)
#define    vOkt(i,l,r)    for(BUEiu    i=(int)(l);i<=(int)(r);i++)
#define    vOktD(i,l,r)    for(BUEiu    i=(int)(l);i>=(int)(r);i--)
#define    tdQlR    pair<double,double>
#define    vGbSi    long    long
#define    Dbw    first
#define    kIoLV    second
#define    XQmRC    push_back
#define    xmI(a,v)    memset(a,v,sizeof(a))
#define    osafI(s)    (int)(s.size())
#define    EL    printf("\n")
#define    digit(x)    ('0'<=x&&x<='9')
#define    forever    while    (Vjt)
#define    usi    unsigned    long    long

const    BUEiu    OO    =    (int)    2e9;
const    BUEiu    MOD    =    (int)    1e9+7;
const    long    double    Pi    =    3.1415926535897932384626433832795;
const    BUEiu    N    =    (int)    1e5+5;

BUEiu    n,m,a,b,tBzGpq=0;
bool    oIy[7];

BUEiu    len(BUEiu    x)     {
                BUEiu    tBzGpq=0;
                while    (x>0)    tBzGpq++,x/=7;
                return    max(1,tBzGpq);
}

bool    eyn(BUEiu    x,BUEiu    y)     {
                //BUEiu    tmpa=x,tmXQmRC=y;
                xmI(oIy,bzD);
                vOkt(i,1,a)     {
                                if    (oIy[x%7])    return    bzD;
                                oIy[x%7]=Vjt;x/=7;
                }
                vOkt(i,1,b)     {
                                if    (oIy[y%7])    return    bzD;
                                oIy[y%7]=Vjt;y/=7;
                }
                return    Vjt;
}

BUEiu    main()     {
                cin>>n>>m;
                a=len(n-1);
                b=len(m-1);
                if    (a+b>7)     {cout<<0;return    0;}
                vOkt(i,0,n-1)    vOkt(j,0,m-1)
                                tBzGpq+=eyn(i,j);
                cout<<tBzGpq;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl

#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define hell 1000000007

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 300009

ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll n,m;cin>>n>>m;

	ll dn=0,dm=0;
	n--;m--;

	ll curr=0;
	rep(i,0,34)
	{
		curr+=6*(pow(7,i));
		if(curr>=n)
		{
			dn=i;
			break;
		}
	}
	curr=0;
	vi v;
	rep(i,0,34)
	{
		curr+=6*(pow(7,i));
		if(curr>=m)
		{
			dm=i;
			break;
		}
	}
	//test2(dn,dm);
	dn++;dm++;
	if(dn + dm >7)
	{
		cout<<0<<endl;
		return 0;
	}
	rep(i,0,7)
	v.pb(i);

	ll ans=0;

	map<pii,ll>mp;
	do
	{
		vi v1;
		for(ll i=0;i<=dn+dm-1;i++)
		v1.pb(v[i]);

		ll hr=0,min=0;
		for(ll i=dn-1;i>=0;i--)
		hr+=v1[i]*(pow(7,dn-1-i));

		for(ll i=dn+dm-1;i>dn-1;i--)
		min+=v1[i]*(pow(7,dn+dm-1-i));

		if(mp[{hr,min}])
		continue;

		//test3("vector",v1[0],v1[1]);
		//test4(hr,n,min,m);
		mp[{hr,min}]=1;
		if(hr<=n and min<=m)
		{
			/*rep(i,0,dn+dm)
			cout<<v[i]<<" ";nl;
			rep(i,0,dn+dm)
			cout<<v1[i]<<" ";nl;

			test3("found answer",hr,min);
			break;*/
			ans++;
		}
	}
	while(next_permutation(all(v)));

	//for(
	cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;

char *tob7(int num, int rad)
{
    char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    int i;
    char buf[66];   /* enough space for any 64-bit in base 2 */

    /* bounds check for radix */
    if (rad < 2 || rad > 62)
        return NULL;
    /* if num is zero */
    if (!num)
        return strdup("0");

    /* null terminate buf, and set i at end */
    buf[65] = '\0';
    i = 65;

    if (num > 0) {  /* if positive... */
        while (num) { /* until num is 0... */
            /* go left 1 digit, divide by radix, and set digit to remainder */
            buf[--i] = digits[num % rad];
            num /= rad;
        }
    } else {    /* same for negative, but negate the modulus and prefix a '-' */
        while (num) {
            buf[--i] = digits[-(num % rad)];
            num /= rad;
        }
        buf[--i] = '-';
    }
    /* return a duplicate of the used portion of buf */
    return strdup(buf + i);
}

bool cmpr(string a, string b)
{
	int n = a.size(),m = b.size();

    string tempa =a, tempb = b;
    sort(tempa.begin(),tempa.end());
    sort(tempb.begin(),tempb.end());
    for(int i =1;i<n;i++)
        if(tempa[i]==tempa[i-1])
            return false;
    for(int i =1;i<m;i++)
        if(tempb[i]==tempb[i-1])
            return false;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(a[i]==b[j])
				return false;
		}
	}
	return true;
}

int main() {
	// your code goes here
	int n,m;

	cin>>n>>m;
	// int maxx = pow(7,6);
	// // if( n > maxx + 1 || m > maxx+1 )
	// // {
	// // 	cout<<"0";
	// // 	return 0;
	// // }

	int temp = 1;
	int numph = 0,numpm=0;
	while(temp < n)
	{
		temp = temp*7;
		numph++;
	}
	temp = 1;
	while(temp < m)
	{
		temp = temp*7;
		numpm++;
	}
	if(m==1)
		numpm = 1;
	if(n==1)
		numph = 1;

	//cout<<numph<<" "<<numpm<<endl;
	if(numph + numpm > 7)
	{
		cout<<"0";
		return 0;
	}

	// vector<int> h(numph,0);
	// vector<int> m(numpm,0);

	int i = 0, j =0;
	long long cnt = 0;
	for(i=0;i<n;i++)
	{
		char* hours = tob7(i,7);
		string hs(hours);
		if(hs.size() < numph - 1)
			continue;
		if(hs.size()<numph && hs[0]=='0' )
			continue;
		if(hs.size()<numph)
			hs = "0" + hs;
		for(j=0;j<m;j++)
		{
			char* mins = tob7(j,7);
			string ms(mins);
			if(ms.size() < numpm - 1)
				continue;
			if(ms.size()<numpm && ms[0]=='0' )
				continue;
			if(ms.size()<numpm)
				ms = "0" + ms;

			if(cmpr(hs,ms))
			{
				 //cout<< hs << " "<<ms<<endl;
				cnt++;
			}
		}
	}
	cout<<cnt;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define maxn 1000007
#define ll long long int
#define db(x) cout<<#x<<" -> "<<x<<" "<<endl
#define db2(x,y) cout<<#x<<"-> "<<x<<", "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++) { cout<<*it<<" "; } cout<<endl
#define IN freopen("input.txt","r",stdin)

vector< int > H , M ;
int dp[15][2][(1<<7)+5];
int X[15][2][(1<<7)+5];

void init(int h, int m){
    while(h){
        H.push_back(h%7);
        h/=7;
    }
    reverse(H.begin(),H.end());
    while(m){
        M.push_back(m%7); m/=7;
    }
    reverse(M.begin(),M.end());
    if(H.size()==0){ H.push_back(0) ; }
    if(M.size()==0){ M.push_back(0) ; }
    return ;
}

int solve(int pos, int small, int mask){
    if(pos==M.size()){
        return 1;
    }
    if(X[pos][small][mask]!=-1){
        return X[pos][small][mask];
    }
    int lim = (small)?6:M[pos];
    int ret = 0;
    if(small){ ///
        for(int i=0; i<=lim; i++){
            if( mask & (1<<i) ){ continue ;}
            ret+=solve(pos+1, small ,  mask|(1<<i) );
        }
    }
    else{
        for(int i=0; i<=lim; i++){
            if( mask & (1<<i) ){ continue ;}
            if(i==lim){
                ret+=solve(pos+1,small,mask|(1<<i));
            }
            else{
                ret+=solve(pos+1,1,mask|(1<<i));
            }
        }
    }
    return X[pos][small][mask]=ret;
}

int recur(int pos,bool small,int mask){
    if(pos==H.size()){
        return solve(0,0,mask);
    }
    if(dp[pos][small][mask]!=-1){
        return dp[pos][small][mask];
    }
    int lim = (small)?6:H[pos];
    int ret = 0;
    if(small){ ///
        for(int i=0; i<=lim; i++){
            if( mask & (1<<i) ){ continue ;}
            ret+= recur(pos+1, small ,  mask|(1<<i) );
        }
    }
    else{
        for(int i=0; i<=lim; i++){
            if( mask & (1<<i) ){ continue ;}
            if(i==lim){
                ret+= recur(pos+1, small , mask|(1<<i));
            }
            else{
                ret+=recur(pos+1,1,mask|(1<<i));
            }
        }
    }
    return dp[pos][small][mask]=ret;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
//    IN;
    int h,m;
    cin>>h>>m;
    h--; m--;
    init(h,m);
//    cout<<H.size()<<" , "<<M.size()<<endl;
    memset(dp,-1,sizeof(dp));
    memset(X,-1,sizeof(X));
    cout<<recur(0,0,0)<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long

int n, m;
vector<int> nv, mv;

main()
{
    cin>>n>>m;

    int t = n-1;

    while(t > 0)
    {
        nv.push_back(t % 7);
        t = t/7;
    }

    t = m-1;

    while(t > 0)
    {
        mv.push_back(t%7);
        t = t/7;
    }

    if(nv.size() + mv.size() >= 8)
    {
        cout<<"0";
        return 0;
    }

    if(nv.size() == 0)
        nv.push_back(0);
    if(mv.size() == 0)
        mv.push_back(0);

    int ans = 0;

    for(int i = 0; i < n; i++)
    {
        vector<int> nt;

        int t = i;

        while(t > 0)
        {
            nt.push_back(t % 7); t = t/7;
        }

        while(nt.size() <  nv.size())
            nt.push_back(0);

        for(int j = 0; j < m; j++)
        {
            vector<int> mt;

            t = j;
            while(t > 0)
            {
                mt.push_back(t%7); t = t/7;
            }

            while(mt.size() < mv.size())
                mt.push_back(0);

            bool hash[7];
            memset(hash, false, sizeof(hash));

            bool con = false;

            for(int k : nt)
            {
                if(hash[k])
                    con = true;
                hash[k] = true;
            }
            for(int k : mt)
            {
                if(hash[k])
                    con = true;
                hash[k] = true;
            }
            if(con)
                continue;
 //           cout<<nt[0]<<nt[1]<<" "<<mt[0]<<mt[1]<<"  "<<i<<" "<<j<<"\n";
//              cout<<i<<" "<<j<<"\n";
        //    cout<<"\n";
            ans++;
        }
    }

    cout<<ans;
}

/*input
8 7
*/
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pii pair<long long,long long>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
vector <string> v1,v2;
string findbin(ll num,ll digits)
{
	string s="";
	while(num>0)
	{
		s = s + (char)(num%7 + 48);
		num = num/7;
	}
	reverse(s.begin(),s.end());
	while(s.length() < digits)
		s = "0"+s;
	return s;
}
int main()
{
	std::ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	ll d1=0;
	ll num=n-1;
	while(num>0)
	{
		d1++;
		num = num/7;
	}
	ll d2=0;
	num=m-1;
	while(num>0)
	{
		d2++;
		num = num/7;
	}
	if(d1+d2>7)
	{
		cout<<"0"<<endl;
		return 0;
	}
	//debug(d1);
	//debug(d2);
	if(d1-1>0)
	{
		ll dig = d1-1;
		ll st = ceil(pow(7,dig-1));
		ll en = ceil(pow(7,dig));
		F(i,st,min(n-1,en-1))
		{
			string s = findbin(i,d1);
			ll l = s.length();
			bool f=0;
			F(i,0,l-1)
			{
				F(j,0,l-1)
				{
					if(i==j)
						continue;
					if(s[i] == s[j])
						f=1;
				}
			}
			if(!f)
				v1.push_back(s);
		}
	}
	if(d1>0)
	{
		ll dig = d1;
		ll st = ceil(pow(7,dig-1));
		ll en = ceil(pow(7,dig));
		F(i,st,min(n-1,en-1))
		{
			string s = findbin(i,d1);
			ll l = s.length();
			bool f=0;
			F(i,0,l-1)
			{
				F(j,0,l-1)
				{
					if(i==j)
						continue;
					if(s[i] == s[j])
						f=1;
				}
			}
			if(!f)
				v1.push_back(s);
		}
	}
	if(d1<=1)
		v1.pb("0");
	if(d2-1>0)
	{
		ll dig = d2-1;
		ll st = ceil(pow(7,dig-1));
		ll en = ceil(pow(7,dig));
		F(i,st,min(m-1,en-1))
		{
			string s = findbin(i,d2);
			ll l = s.length();
			bool f=0;
			F(i,0,l-1)
			{
				F(j,0,l-1)
				{
					if(i==j)
						continue;
					if(s[i] == s[j])
						f=1;
				}
			}
			if(!f)
				v2.push_back(s);
		}
	}
	if(d2>0)
	{
		ll dig = d2;
		ll st = ceil(pow(7,dig-1));
		ll en = ceil(pow(7,dig));
		F(i,st,min(m-1,en-1))
		{
			string s = findbin(i,d2);
			ll l = s.length();
			bool f=0;
			F(i,0,l-1)
			{
				F(j,0,l-1)
				{
					if(i==j)
						continue;
					if(s[i] == s[j])
						f=1;
				}
			}
			if(!f)
				v2.push_back(s);
		}
	}
	if(d2<=1)
		v2.pb("0");
	ll sz1 = v1.size();
	ll sz2 = v2.size();
	ll ans=0;
	F(i,0,sz1-1)
	{
		string s1 = v1[i];
		ll l1 = s1.length();
		//cout<<s1<<endl;
		F(j,0,sz2-1)
		{
			string s2 = v2[j];
			//cout<<s2<<" ";
			ll l2 = s2.length();
			bool f=0;
			F(i,0,l1-1)
			{
				F(j,0,l2-1)
				{
					if(s1[i] == s2[j])
					{
						f=1;
						break;
					}

				}
				if(f)
					break;
			}
			if(!f)
			{
				ans++;
				//cout<<s1<<" "<<s2<<endl;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>

#define pb push_back
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend();
#define fr first
#define se second
#define mp make_pair
#define sz(a) ll((a).size())
#define memo(a,b) memset(a,b,sizeof(a))
#define MAX 100001
#define INF 1e18+1

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

ll n,m,t,ans,x,y;
bool f[7],br;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  cin>>n>>m;

  t = n-1;
  while(t > 0){ t/=7;++x;}

  t = m-1;
  while(t > 0){t/=7;++y;}

  if(n == 1) x = 1;if(m == 1) y = 1;

  if(x + y > 7){cout<<0<<endl;return 0;}

  for(ll i = 0;i < n;++i){
    for(ll j = 0;j < m;++j){
      memo(f,false);br = true;
      t = i;

      for(ll u = 0;u < x;++u){
	if(!f[t%7]) f[t%7] = true;
	else br = false;
	t /= 7;
      }

      t = j;
      for(ll u = 0;u < y;++u){
	if(!f[t%7]) f[t%7] = true;
	else br = false;
	t /= 7;
      }

      if(br) ++ans;
    }
  }

  cout<<ans<<endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define sc(x)            scanf("%d",&x)
#define scc(x)           scanf("%c",&x)
#define scl(x)           scanf("%lld",&x)
#define sz(v)	     	(v.size())
#define mem(v, d)		memset(v, d, sizeof(v))
#define oo				2000000100
#define OO				4000000000000000100
#define PI 3.14159265
typedef unsigned int uint;
typedef long long ll;
//-----------------------------------------------------
const int N = 500005;
const ll MOD = 998244353;

int dX[] = {0,0,1,-1};
int dY[] = {1,-1,0,0};

//ll GCD(ll num,ll ones) { return !ones ? num : GCD(ones,num%ones); }
//ll lcm(ll a, ll b) { return (a / GCD(a, b)) * b; }
//double Len(int x,int y,int X,int Y) { return sqrt((X-x)*(X-x)+(Y-y)*(Y-y)); }
/*ll fastP(ll b,ll p)
{
    if(p==0) return 1;
    else if(p==1) return b;
    ll a = fastP(b,p/2)%MOD;
    if(p%2) return (((a*a)%MOD)*b)%MOD;
    else return (a*a)%MOD;
}*/
//----------------- ------   -------
int n,m; string H = "",M = "",tmp;
string Conv(int x)
{
    string ret = "";
    if(!x) ret = "0";
    while(x)
    {
        ret+=( (x%7) + '0');
        x/=7;
    }
    reverse(ret.begin(),ret.end());
    return ret;
}
int solve2(string s = "",bool f = 0)
{
    if(sz(s) == sz(M)) return 1;
    int ret = 0;
    for(char c = '0'; c<='6' ; ++c)
    {
        if(!f && c>M[sz(s)]) break;
        if(!count(s.begin(),s.end(),c) && !count(tmp.begin(),tmp.end(),c)) ret += solve2(s+c,f || c<M[sz(s)]);
    }
    return ret;
}
int solve(string s = "",bool f = 0)
{
    if(sz(s) == sz(H)) return tmp = s,solve2();
    int ret = 0;
    for(char c = '0'; c<='6' ; ++c)
    {
        if(!f && c>H[sz(s)]) break;
        if(count(s.begin(),s.end(),c) == 0) ret += solve(s+c,f || c<H[sz(s)]);
    }
    return ret;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("i.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    sc(n); sc(m); n--; m--;
    H = Conv(n);
    M = Conv(m);
    if(sz(H)+sz(M) > 7) return puts("0");
    cout<<solve();

    return 0;
}

#include <algorithm>
#include <iostream>
#include <cmath>
#include <fstream>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <memory.h>

using namespace std;

typedef unsigned long long ll;
typedef long double ld;

template <typename T>
T gcd(T a, T b) {
    while (a > 0 && b > 0) {
        if (a > b) a %= b; else b %= a;
    }
    return (a + b);
}

template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template <typename T>
bool prime(T n) {
    if (n <= 1) {
        return false;
    }
    T i = 2;
    while (i * i <= n) {
        if (n % i == 0) {
            return false;
        }
        ++i;
    }
    return true;
}

ll get(ll n) {
    int len = 0;
    while (n) {
        len += 1;
        n /= 7;
    }
    return max(1, len);
}

void solveTask() {
    ll a, b;
    cin >> a >> b;
    ll lenA = get(a - 1), lenB = get(b - 1);
    if (lenA + lenB > 7) {
        cout << 0 << endl;
        return;
    }
    int ans = 0;
    for (int A = 0; A < a; ++A) {
        for (int B = 0; B < b; ++B) {
            map<int, int> mp;
            int tmp = A;
            for (int i = 0; i < lenA; ++i) {
                mp[tmp % 7] += 1;
                tmp /= 7;
            }
            tmp = B;
            for (int i = 0; i < lenB; ++i) {
                mp[tmp % 7] += 1;
                tmp /= 7;
            }
            bool ok = true;
            for (map<int, int> :: iterator it = mp.begin(); it != mp.end(); ++it) {
                pair<int, int> cur = *it;
                if (cur.second > 1) ok = false;
            }
            if (ok) {
               ++ans;
            }
        }
    }
    cout << ans << endl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    solveTask();
    return 0;
}

#include<bits/stdc++.h>
#define WR "txt"

void Open() { freopen(WR".in", "r", stdin); freopen(WR".out", "w", stdout); }
void Close() { fclose(stdin); fclose(stdout); }
using namespace std;
int Read()  {
	int val = 0, opt = 1; char ch;
	while (!isdigit(ch = getchar() )) if (ch == '-') opt = -1;
	while (isdigit( ch )) (val *= 10) += ch - '0', ch= getchar();
	return val * opt;
}

int A[20], B[20], Ans, Num[10], Vis[10];

void dfs(int t, int Max)  {
	if (t > Max)  {
		for (int i = A[0]; i; i--)  {
			if (A[i] > Num[i]) break;
			if (A[i] < Num[i]) return ;
		}
		for (int i = B[0]; i; i--)  {
			if (B[i] > Num[i + A[0]]) break;
			if (B[i] < Num[i + A[0]]) return ;
		}
		Ans++;
		return ;
	}
	for (int i = 0;i < 7; i++)
		if (!Vis[i])  {
			Vis[i] = 1;
			Num[t] = i;
			dfs(t + 1, Max);
			Vis[i] = 0;
		}
}

void Change(int x, int a[])  {
	if (!x)  {
		a[++a[0]] = 0;
	}
	while (x)  {
		a[++a[0]] = x % 7;
		x /= 7;
	}
}

void work()  {
	Change(Read() - 1, A);
	Change(Read() - 1, B);
	if (A[0] + B[0] > 7
	)  {
		printf("0\n");
		return ;
	}
	dfs(1, A[0] + B[0]);
	printf("%d\n", Ans);
}

int main(void)  {
	//Open();
	work();
	//Close();
	return 0;
}

#define JvJiUm false
#define VWQIDB true
#define NLSJvJq  char
#define JvJsQmR  int
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <string>
#include <string.h>
#include <iostream>
#include <queue>
using namespace std;
#define fi "input.txt"
#define fo "output.txt"
#define Fyt freopen(fi,"r",stdin);freopen(fo,"w",stdout)
#define kRVWQI(i,l,r) for(JvJsQmR i=(int)(l);i<=(int)(r);i++)
#define kRVWQID(i,l,r) for(JvJsQmR i=(int)(l);i>=(int)(r);i--)
#define Qvwk pair<double,double>
#define bGL long long
#define JvJ first
#define VWQ second
#define Hfy push_back
#define ZPjTK(a,v) memset(a,v,sizeof(a))
#define ljY(s) (int)(s.size())
#define EL printf("\n")
#define digit(x) ('0'<=x&&x<='9')
#define forever while (VWQIDB)
#define usi unsigned long long

const JvJsQmR OO = (int) 2e9;
const JvJsQmR MOD = (int) 1e9+7;
const long double Pi = 3.1415926535897932384626433832795;
const JvJsQmR N = (int) 1e5+5;

JvJsQmR n,m,a,b,AeC=0;
bool HaJvJZ[7];

JvJsQmR len(JvJsQmR x) {
    JvJsQmR AeC=0;
    while (x>0) AeC++,x/=7;
    return max(1,AeC);
}

bool AFbL(JvJsQmR x,JvJsQmR y) {
    //JvJsQmR tmpa=x,tmHfy=y;
    ZPjTK(HaJvJZ,JvJiUm);
    kRVWQI(i,1,a) {
        if (HaJvJZ[x%7]) return JvJiUm;
        HaJvJZ[x%7]=VWQIDB;x/=7;
    }
    kRVWQI(i,1,b) {
        if (HaJvJZ[y%7]) return JvJiUm;
        HaJvJZ[y%7]=VWQIDB;y/=7;
    }
    return VWQIDB;
}

JvJsQmR main() {
    cin>>n>>m;
    a=len(n-1);
    b=len(m-1);
    if (a+b>7) {cout<<0;return 0;}
    kRVWQI(i,0,n-1) kRVWQI(j,0,m-1)
        AeC+=AFbL(i,j);
    cout<<AeC;
}

#define JXDsJit false
#define pCVx true
#define FsUGIJXDsJipk  char
#define mlO  int
#include  <stdio.h>
#include  <algorithm>
#include  <vector>
#include  <map>
#include  <set>
#include  <math.h>
#include  <string>
#include  <string.h>
#include  <iostream>
#include  <queue>
using  namespace  std;
#define  fi  "input.txt"
#define  fo  "output.txt"
#define  UmIU  freopen(fi,"r",stdin);freopen(fo,"w",stdout)
#define  hsN(i,l,r)  for(mlO  i=(int)(l);i<=(int)(r);i++)
#define  hsND(i,l,r)  for(mlO  i=(int)(l);i>=(int)(r);i--)
#define  HPsZC  pair<double,double>
#define  ihV  long  long
#define  FsUGI  first
#define  XDsJi  second
#define  wpM  push_back
#define  qBvDi(a,v)  memset(a,v,sizeof(a))
#define  ULrF(s)  (int)(s.size())
#define  EL  printf("\n")
#define  digit(x)  ('0'<=x&&x<='9')
#define  forever  while  (pCVx)
#define  usi  unsigned  long  long

const  mlO  OO  =  (int)  2e9;
const  mlO  MOD  =  (int)  1e9+7;
const  long  double  Pi  =  3.1415926535897932384626433832795;
const  mlO  N  =  (int)  1e5+5;

mlO  n,m,a,b,keKDK=0;
bool  VXDsJiHfuC[7];

mlO  len(mlO  x)  {
        mlO  keKDK=0;
        while  (x>0)  keKDK++,x/=7;
        return  max(1,keKDK);
}

bool  VAaH(mlO  x,mlO  y)  {
        //mlO  tmpa=x,tmwpM=y;
        qBvDi(VXDsJiHfuC,JXDsJit);
        hsN(i,1,a)  {
                if  (VXDsJiHfuC[x%7])  return  JXDsJit;
                VXDsJiHfuC[x%7]=pCVx;x/=7;
        }
        hsN(i,1,b)  {
                if  (VXDsJiHfuC[y%7])  return  JXDsJit;
                VXDsJiHfuC[y%7]=pCVx;y/=7;
        }
        return  pCVx;
}

mlO  main()  {
        cin>>n>>m;
        a=len(n-1);
        b=len(m-1);
        if  (a+b>7)  {cout<<0;return  0;}
        hsN(i,0,n-1)  hsN(j,0,m-1)
                keKDK+=VAaH(i,j);
        cout<<keKDK;
}

#include <bits/stdc++.h>
#define LL long long int
#define ULL unsigned long long int
using namespace std;

set<LL>answer;
LL convertTo7(LL ten){
    if (ten==0) return 1;
    int seven=0;
    while (ten){
        seven++;
        ten/=7;
    }
    return seven;
}
int main() {
    LL hours,minutes;
    cin >> hours >> minutes;
    LL sum=convertTo7(hours-1)+convertTo7(minutes-1);
    if (sum>7){
        cout << '0';
        return 0;
    }
    LL leftHalf=convertTo7(hours-1),rightHalf=convertTo7(minutes-1);
    LL arr[7];
    for (int i=0;i<7;i++) arr[i]=i;
    do{
        LL watch[2]={0,0};
        for (LL i=0;i<leftHalf;i++)
            watch[0]=watch[0]*7+arr[i];
        for (LL i=leftHalf;i<leftHalf+rightHalf;i++)
            watch[1]=watch[1]*7+arr[i];
        if (watch[0]<hours and watch[1] < minutes) answer.insert
                    (watch[0]*1000000000+watch[1]);

    } while (next_permutation(arr,arr+7));
    cout << answer.size();
}

#define push_back pb
#define make_pair mk
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<map>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using std::pair;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<PII,int> PPI;
typedef pair<ll,int> PLI;
const double PI=acos(-1);
const int maxn = 10000 + 10;
const int maxm = 100 + 10;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
using namespace std;
int len1,len2;
int getlen(int n)
{
    int ret=0;
    while(n)
    {
        n/=7;
        ret++;
    }
    return ret;
}
int vis[10];
int check(int n,int len)
{
    int num=0;
    while(n)
    {
        if(vis[n%7]) return 0;
        vis[n%7]=1;
        n/=7;
        num++;
    }
    for(int i=num;i<len;i++)
    {
        if(vis[0]) return 0;
        vis[0]=1;
    }
    return 1;
}
int main()
{
    int n,m;
    cin>>n>>m;
    len1=getlen(n-1);
    len2=getlen(m-1);
    if(len1==0) len1++;
    if(len2==0) len2++;
   //cout<<len1<<" "<<len2<<endl;
    int res=0;
    if(len1+len2<=7)
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                memset(vis,0,sizeof(vis));
                if(i==j||(!check(i,len1)||!check(j,len2))) continue;
                res++;
            }
        }
    }
    cout<<res<<endl;
}

#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

#define nln        puts("")                         ///prLLInewline
#define getLLI(a)  scanf("%d",&a);
#define mx3(a,b,c) mx(a,mx(b,c))                  ///3 ta theke mx
#define min3(a,b,c) min(a,min(b,c))                  ///3 ta theke min

#define FOR1(i,n)  for(LLI i=1;i<=n;i++)
#define FOR0(i,n)  for(LLI i=0;i<n;i++)                 ///looping
#define FORR(i,n)  for(LLI i=n-1;i>=0;i--)
#define ALL(p)     p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define SZ(c)      (LLI)c.size()
#define PB(x)      push_back(x)                     ///STL defines
#define MP(x,y)    make_pair(x,y)
#define ff         first
#define ss         second

#define LI         long LLI
#define LLI        long long
#define f64        long double
#define PI         acos(-1.0)                        ///PI er value

LLI Set(LLI N,LLI pos)
{
    return N=N | (1ll<<pos);
}
LLI reset(LLI N,LLI pos)
{
    return N= N & ~(1ll<<pos);
}
bool check(LLI N,LLI pos)
{
    return (bool)(N & (1ll<<pos));
}
void CI(LLI &_x)
{
    scanf("%d",&_x);
}

void CO(LLI &_x)
{
    cout<<_x;
}

template<typename T> void getarray(T a[],LLI n)
{
    for(LLI i=0; i<n; i++) cin>>a[i];
}
template<typename T> void prLLIarray(T a[],LLI n)
{
    for(LLI i=0; i<n-1; i++) cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
}

const double EPS=1e-9;                              ///constatnts
const LLI INF=0x7f7f7f7f;

LLI dr8[8]= {1,-1,0,0,1,-1,-1,1};            ///8 direction move
LLI dc8[8]= {0,0,-1,1,1,1,-1,-1};
LLI dr4[4]= {0,0,1,-1};                      ///4 direction move
LLI dc4[4]= {-1,1,0,0};                      ///or adjacent dir.
LLI kn8r[8]= {1,2,2,1,-1,-2,-2,-1};          ///knight moves
LLI kn8c[8]= {2,1,-1,-2,-2,-1,1,2};
LLI sz=0;
LLI decimal_to_7_base(LLI num)
{
    if(num==0){

        sz=1;
        return 0;
    }
    vector<LLI>V;
    while(num)
    {

        V.PB(num%7);
        num/=7;
    }
    sz=V.size();
    reverse(ALL(V));
    LLI nn=0;
    for(LLI i=0; i<V.size(); i++)
    {
        nn=(nn*10)+V[i];
    }
    return nn;
}
LLI num;
vector<LLI>V;
void backtrack(LLI pos,LLI mask,LLI nn)
{
    if(pos==sz)
    {
        if(nn<=num)
        {

            V.PB(mask);
        }

        return ;
    }
    for(LLI i=0; i<7; i++)
        if(check(mask,i)==0)
        {
            backtrack(pos+1,Set(mask,i),(nn*10)+i);
        }

}
vector<LLI>digit;
LLI dp[20][1<<10][3];
LLI rec(LLI pos,LLI mask,LLI eq)
{
    if(pos==0)return 1;

    if(eq==0&&dp[pos][mask][eq]!=-1)return dp[pos][mask][eq];

    LLI ans=0;
    for(LLI i=0; i<7; i++)
        if(check(mask,i)==0)
        {
            if(eq==1)
            {
                if(i==digit[pos-1])
                    ans+=rec(pos-1,Set(mask,i),eq);
                else if(i<digit[pos-1])
                    ans+=rec(pos-1,Set(mask,i),0);
            }
            else
            {
                ans+=rec(pos-1,Set(mask,i),0);

            }

        }
        dp[pos][mask][eq]=ans;
    return ans;

}
void base_conv(LLI num)
{
    if(num==0){

        digit.PB(num);
        return ;
    }
    while(num)
    {
        digit.PB(num%7);
        num/=7;
    }
    // return digit;
}
int main()
{
    memset(dp,-1,sizeof dp);
    LLI n,m;
    cin>>n>>m;
    num=decimal_to_7_base(n-1);
    backtrack(0,0,0);
    base_conv(m-1);
    LLI ans=0;
    for(LLI i=0; i<V.size(); i++)
    {

        LLI mask=V[i];
//        for(LLI j=0; j<7; j++)
//            if(check(mask,j)==1)
//                cout<<j;
//        puts("");
//        cout<<"FF : "<<rec(digit.size(),mask,1)<<"\n";
        ans+=rec(digit.size(),mask,1);

    }
    cout<<ans<<"\n";
}

#include <bits/stdc++.h>
using namespace std;

string toSeven(const int& x, const int& maxs){
	string s;
	if(!maxs) return "0";
	int p = maxs;
	int u = 7;
	int xx = x;
	while(p){
		s += xx % 7 + '0';
		xx /= 7;
		p /= 7;
	}
	reverse(s.begin(), s.end());
	return s;
}

int main() {
	int n, m; cin >> n >> m;

	--n, --m;

	int sizes = toSeven(n, n).size() + toSeven(m, m).size();

	if(sizes > 7){
		cout << 0 << endl;
		return 0;
	}
	long long count = 0;

	for(int i = 0; i <= n; ++i){
		for(int j = 0; j <= m; ++j){
			set<char> ss;
			string s = toSeven(j, m);
			//cout << s << ' ';
			for(int t = 0; t < s.size(); ++t)
				ss.insert(s[t]);

			//string g = s;
			s = toSeven(i, n);
			//cout << s << endl;;
			for(int t = 0; t < s.size(); ++t)
				ss.insert(s[t]);
			if(ss.size() == sizes){
				//cout << g + s << endl;
				++count;
			}
		}
	}
	cout << count << endl;
}

#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	int N = 1, M = 1;
	for(ll i = 7; i < n; i*=7) ++N;
	for(ll j = 7; j < m; j*=7) ++M;
	if(N+M > 7){
		cout << 0 << endl;
		return 0;
	}
	int ans = 0;
	rep(i,n)rep(j,m){
		vector<int> used(7, 0);
		int mx = 0;
		for(int a = i, k = 0; k < N; a /= 7, ++k) chmax(mx, ++used[a%7]);
		for(int b = j, k = 0; k < M; b /= 7, ++k) chmax(mx, ++used[b%7]);
		ans += (mx <= 1);
	}
	cout << ans << endl;
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#include <sstream>
#include <queue>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;

#define mp make_pair
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define forr(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define forit(i,c) for(i=(c).begin(); i!=(c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef vector<int> vint;
typedef vector<bool> vbool;
typedef vector<int64> vint64;
typedef pair<int, int> pii;
typedef pair<int64, int64> pii64;

typedef map<int64, int> mii;

vint Sem(int n)
{
	vint v;
	while (n != 0)
	{
		v.push_back(n % 7);
		n /= 7;
	}
	return v;
}

int main()
{
#ifdef _VLYZ
	freopen("input.txt", "r", stdin);
#else
	//freopen("abc.in", "r", stdin);
	//freopen("abc.out", "w", stdout);
#endif

	int n, m;
	cin >> n >> m;
	int kn = Sem(n - 1).size();
	int km = Sem(m - 1).size();
	int64 res = 0;
	if (kn + km > 7)
	{
		cout << res << endl;
		return 0;
	}
	forn(i, n)
	{
		forn(j, m)
		{
			vint a = Sem(i);
			vint b = Sem(j);
			if (a.size() > kn)
			{
				cout << res << endl;
				return 0;
			}
			if (b.size() > km) break;
			vint c(7);
			forn(g, a.size())
			{
				c[a[g]]++;
			}
			forn(g, b.size())
			{
				c[b[g]]++;
			}
			c[0] += km + kn - a.size() - b.size();
			bool f = true;
			forn(g, c.size())
			{
				if (c[g] > 1)
				{
					f = false;
					break;
				}
			}
			if (f) ++res;
		}
	}
	cout << res << endl;

	return 0;
}

#include <iostream>
#include <cstring>
#include <math.h>
using namespace std;
#include <set>
bool combine(long long int *hr,long long int *min,long long int max_hr,long long int max_min){
	set<long long int> s;
	long long int i,j;
	for(i=0;i<=max_hr;i++){
		s.insert(hr[i]);
	}
	for(i=0;i<=max_min;i++){
		s.insert(min[i]);
	}
	int size=int(s.size());
	if(size==max_hr+max_min+2){
		/*for(i=0;i<=max_hr;i++)
			cout << hr[max_hr-i];
		cout << ":";
		for(i=0;i<=max_min;i++)
			cout << hr[max_min-i];*/
		return true;
	}
	else
		return false;
}

bool check(long long int *hr,long long int max_hr){
	set<long long int> s;
	int i,j;
	for(i=0;i<=max_hr;i++){
		s.insert(hr[i]);
	}
	int size=int(s.size());
	if(size==max_hr+1)
		return true;
	else
		return false;
}

void rep(long long int* hr,long long int val,long long int max_pow,long long int *power){
	int i=0;
	long long int rem=val;
	for(i=max_pow;i>=0;i--){
		hr[i]=rem/power[i];
		rem=rem%power[i];
	}
}

//void rep_min(long long int* min,long long int val,long long int )

long long int pow7(int n){
	int pro=1,i=0;
	for(i=0;i<n;i++){
		pro=pro*7;
	}
	return pro;
}

int main(){
	long long int n,m,i,j,*power,*hr,*min,max_pow_hr,max_pow_min,count=0;
	cin >> n >> m;
	power=new long long int[7];
	for(i=0;i<7;i++){
		power[i]=pow7(i);
		//cout << power[i] << endl;
	}
	max_pow_hr=(int)(log10(n)/log10(7));
	max_pow_min=(int)(log10(m)/log10(7));
	hr=new long long int[max_pow_hr+1];
	min=new long long int[max_pow_min+1];
	if(max_pow_min+max_pow_hr+2>7){
		cout << "0";
	}
	else{
		i=0;
		for(j=0;j<=max_pow_hr;j++)
			i+=power[j]*(max_pow_hr-j);
		for(j=0;j<=max_pow_min;j++)
			min[j]=0;
		for(;i<n;i++){
			rep(hr,i,max_pow_hr,power);
			if(check(hr,max_pow_hr)==true){
				for(j=0;j<m;j++){
					rep(min,j,max_pow_min,power);
					if(combine(hr,min,max_pow_hr,max_pow_min)==true)
						count=count+1;
				}
			}
		}
	}
	/*for(i=0;i<5;i++){
		cin >> m ;
		rep(hr,m,n,max_pow_hr,power);
		j=max_pow_hr;
		while(j>=0){
			cout << hr[j];
			j--;
		}
		cout << endl;
	}*/
	cout << count << endl;
	return 0;
}

//#pragma comment(linker, "/STACK:102400000,102400000")
#pragma warning(disable:4996)
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

#define eps 1e-5
#define LL_INF 0x3fffffffffffffff
#define INF 0x3fffffff
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 1e3 + 5;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);

ll res;
int n, m, cnt, d1, d2;
int dig[maxn], vis[maxn];

void dfs(int num, int end, int d1, int d2)
{
	if (num == d2 + 1)
	{
		res++;
		return;
	}
	int i, j, k;
	int up = end == 1 ? dig[num] : 6;

	if (num == d1 + 1)
	{
		up = dig[num];
		end = 1;
	}
	for (i = 0; i <= up; i++)
	{
		if (!vis[i])
		{
			vis[i] = 1;
			if (i == up)
			{
				dfs(num + 1, end & 1, d1, d2);
			}
			else
			{
				dfs(num + 1, 0, d1, d2);
			}
			vis[i] = 0;
		}
	}

}

void solve()
{
	int i, j, k;
	cin >> n >> m;
	cnt = 0;
	n--;
	m--;
	do
	{
		cnt++;
		dig[cnt] = n % 6;
		n /= 6;
	} while (n > 0);
	d1 = cnt;
	do
	{
		cnt++;
		dig[cnt] = m % 6;
		m /= 6;
	} while (m > 0);

	res = 0;
	dfs(1, 1, d1, cnt);
	printf("%lld", res);
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("i.txt", "r", stdin);
	freopen("o.txt", "w", stdout);
#endif
	solve();
	return 0;
}

#include <bits/stdc++.h>

#ifdef LOCAL_COMP
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL(0,__VA_ARGS__, 5,4,3,2,1)
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N

#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro ## nargs

#define debug(...) macro_dispatcher(debug, __VA_ARGS__)(__VA_ARGS__)

#define debug1(a)       cout<< #a << " = " << (a) << endl
#define debug2(a,b)     cout<< #a << " = " << (a) << "  " << #b << " = " << (b) << endl
#define debug3(a,b,c)   cout<< #a << " = " << (a) << "  " << #b << " = " << (b) << "  " \
  << #c << " = " << (c) << endl
#define debug4(a,b,c,d) cout<< #a << " = " << (a) << "  " << #b << " = " << (b) << "  " \
  << #c << " = " << (c) << "  " << #d << " = " << (d) << endl
#else
#define debug(...)
#endif

using namespace std;

typedef long long T;

T pow2[20];

int convert(T x, T size) {
  int mask = 0;

  while (x > 0) {
    int mod = x % 7;
    if (mask & pow2[mod]) {
      return -1;
    }
    mask |= pow2[mod];
    x /= 7;
    --size;
  }

  if (size >= 2) {
    return -1;
  }

  if (size == 1) {
    if (mask & pow2[0]) {
      return -1;
    } else {
      mask |= pow2[0];
    }
  }

  return mask;
}

int get_size(int x) {
  int size = 0;

  while (x > 0) {
    ++size;
    x /= 7;
  }

  if (size == 0) {
    size = 1;
  }

  return size;
}

T stupid_check(T a_mask, T b_mask) {
  if (a_mask & b_mask) {

  } else {
    if (a_mask >= 0 && b_mask >= 0) {
      return true;
    }
  }
  return false;
}

T stupid_solve(T n, T m) {
  int n_size = get_size(n), m_size = get_size(m);

  T ret = 0;
  for (int a = 0; a < n; ++a) {
    for (int b = 0; b < m; ++b) {
      int a_mask = convert(a, n_size), b_mask = convert(b, m_size);
      if (stupid_check(a_mask, b_mask)) {
        ++ret;
      }
    }
  }
  return ret;
}

T calc(T hours, T minutes, T n, T m) {

}

T solve(T n, T m = -1) {
  if (m < 0) {
    cin >> m;
  }

  int base_n_size = get_size(n), base_m_size = get_size(m);

  if (base_n_size + base_m_size > 7) {
    return 0;
  }

  int n_size = base_n_size, m_size = base_m_size;

  T ret = 0;
  for (T a = 0; get_size(a) <= n_size && a < n; ++a) {
    for (T b = 0; get_size(b) <= m_size && b < m; ++b) {
      int a_mask = convert(a, n_size), b_mask = convert(b, m_size);
      if (stupid_check(a_mask, b_mask)) {
        ++ret;
      }
    }
  }

  return ret;

  int total_size = n_size + m_size;

  for (T a = 0; ; ++a) {
    if (get_size(a) > total_size) {
      break;
    }

    int mask = convert(a, total_size);
    if (mask < 0) {
      continue;
    }

    vector<int> digs;
    T cur = a;
    for (int i = 0; i < total_size; ++i) {
      digs.push_back(cur % 7);
      cur /= 7;
    }
    reverse(digs.begin(), digs.end());

    vector<int> lefts(total_size, 0);
    lefts[0] = digs[0];
    for (int i = 1; i < total_size; ++i) {
      lefts[i] = lefts[i - 1] * 7 + digs[i];
    }

    vector<int> rights(total_size, 0);
    rights[total_size - 1] = digs[total_size - 1];
    T seven = 7;
    for (int i = total_size - 2; i >= 0; --i) {
      rights[i] = digs[i] * seven + rights[i + 1];
      seven *= 7;
    }
//    reverse(rights.begin(), rights.end());

    for (int i = 0; i < n_size; ++i) {
//      T left_mask = convert(lefts[i], n_size), right_mask = convert(rights[i], m_size);
      if (lefts[i] < n && rights[i + 1] < m) {
        ++ret;
      }
    }
  }

//  cout << ret << endl;
  return ret;
}

int main() {
#ifdef LOCAL_COMP
  freopen("a.txt", "r", stdin);
#endif

  pow2[0] = 1;
  for (int i = 1; i < 20; ++i) {
    pow2[i] = pow2[i - 1] * 2;
  }

//  for (int iter = 0; iter < 1000; ++iter) {
//    T n = rand() % 10000 + 1;
//    T m = rand() % 10000 + 1;
////  for (int n = 1; n < 100; ++n) {
////    for (int m = 1; m < 100; ++m) {
//      T stupid = stupid_solve(n, m);
//      T smart = solve(n, m);

//      debug(n, m, stupid, smart);
//      assert(stupid == smart);
////    }
//  }

#if 1
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  for (int n; cin >> n; ) {
    cout << solve(n) << endl;
//    while(n--) {
//      solve(n);
//    }
//    if (solve(n)) {
//      cout << "YES" << endl;
//    } else {
//      cout << "NO" << endl;
//    }
  }
  cout.flush();
#else
  int n;
  while (scanf("%d", &n) == 1) {
    solve(n);
  }
#endif

  return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int g[10];
bool b[10];
int i,j,k,l,m,n,r,s,t,tt,ttt;

int main()
{
	scanf("%d%d",&n,&m);
	for (k=n;k>0;k=k/7)
		tt++;
	for (k=m,t=tt;k>0;k=k/7)
		t++;
	if (t>7)
	{
		printf("0");
		return 0;
	}
	for (i=1;i<=t;i++)
		g[i]=i-1;
	ttt=1;
	for (i=1;i<=t;i++)
		ttt=ttt*7;
	for (i=1;i<=ttt;i++)
	{
		r=1;
		memset(b,false,sizeof(b));
		for (j=1;j<=t;j++)
			if (! b[g[j]])
				b[g[j]]=true;
			else
				r=0;
		for (k=1,l=0;k<=tt;k++)
			l=l*7+g[k];
		if (l>=n)
			r=0;
		for (k=tt+1,l=0;k<=t;k++)
			l=l*7+g[k];
		if (l>=m)
			r=0;
		s=s+r;
		g[t]++;
		for (j=t;j>0;j--)
			if (g[j]==7)
				g[j]=0,g[j-1]++;
	}
	printf("%d",s);
	return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define ll long long int
ll ft,sd;ll n,m;
ll solve1(ll mask,ll mi,ll cnt)
{
	ll ans=0;
	if(cnt==sd&&mi<=m)return 1;
	if(cnt==sd)return 0 ;
	for(ll i=0;i<7;i++)
	{
		if(((mask)&(1<<i))==0)
		{
			ans+=solve1((mask|(1<<i)),mi+pow(7,cnt)*i,cnt+1);
		}
	}
	return ans;
}
ll solve(ll mask,ll no,ll cnt)
{
	ll ans=0;
	if(cnt==ft&&no<=n){ans+=solve1(mask,(ll)0,(ll)0);return ans;}
	if(cnt==ft)return 0 ;
	for(ll i=0;i<7;i++)
	{
		if(((mask)&(1<<i))==0)
		{
			ans+=solve((mask|(1<<i)),no+pow(7,cnt)*i,cnt+1);
		}
	}
	return ans;
}
int main()
{
	cin>>n>>m;n--,m--;
	ll base=7;if(n<7)ft=1;else if(n==7)ft=2;
	else
	{
		ft=log(n)/log(7)+1;
	}
	if(m<7)sd=1;
	else if(m==7)sd=2;
	else sd=log(m)/log(7)+1;
	//cout<<ft<<" "<<sd<<endl;
	if(ft+sd>7)
	{
		cout<<0<<endl;return 0;
	}
	ll  ans=1;
	cout<<solve((ll)0,(ll)0,(ll)0)<<endl;
}

#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;

int main()
{
    int N,M;
    cin>>N>>M;

    int c1=0,c2=0;

    int t1=N-1,t2=M-1;

    while(t1)
    {
        c1++;
        t1=t1/7;
    }
    cout<<c1<<endl;
    while(t2)
    {
        c2++;
        t2=t2/7;
    }
    cout<<c2<<endl;
    cout<<c1+c2<<endl;
    if(c1+c2>7)cout<<0;
    else{
        ll ans=0;
        for(int h=0;h<N;h++)
        for(int m=0;m<M;m++)
        {
            t1=h;
            t2=m;
            vector<int>a(7,0);
            for(int k=0;k<c1;k++)
            {
                a[t1%7]++;
                t1=t1/7;
            }
            for(int k=0;k<c2;k++)
            {
                a[t2%7]++;
                t2=t2/7;
            }
            int flag=1;
            for(int i=0;i<7;i++)if(a[i]>1)flag=0;
            if(flag)ans++;
        }
        cout<<ans;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
//#pragma GCC target("popcnt")  //https://godbolt.org/z/yQv94Y

typedef long long int ll;
typedef unsigned long long int  ull;
typedef long double ld;

#define INF 1e9
#define pi 3.141592653589
#define e 2.718281828459
#define phi 1.618033988749
#define MOD 1000000007
#define printarr(arr,n){for(int i=0;i<(n);i++){cout<<arr[i]<<" ";}cout<<endl;}
#define foreach(it , l) for(auto it = l.begin(); it != l.end(); ++it)
#define xlr8 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define rev_sort(a) sort(a.rbegin(),a.rend());

struct Timer
{
    chrono::time_point<chrono::high_resolution_clock> start , end;
    chrono:: duration<float> dur;
    Timer()
    {
        start = chrono::high_resolution_clock::now();
    }
    ~Timer()
    {
        end = chrono::high_resolution_clock::now();
        dur = end - start;
        cout<<"\nTime Elapsed : " <<dur.count() << " s\n";
    }
};

ll sum() {return 0;}
template<typename T, typename... Args>
T sum(T a , Args... args)   {return a + sum(args...); }

//76149
template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template<typename... Args>
  Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
  }
};
template<typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, T val = T()) : vector<T>(n, val) {
  }
};

ll n , m;
vector<int> a,b;
const int MAX = 20;
const int MAX2 = (1<<7);
int N , M;
int dp[MAX][2][2][MAX2];
vector<int> res;
int solve(int i , int lo1 , int lo2 ,  int mask)
{
    if(i == N + M)
        {
            if(N==0 && M== 0)
                return 0;

            else if(M == 0 || N == 0)
                return (mask%2 == 0);

            // for(auto x : res)
            //     cout<<x<<" ";
            // cout<<"\n";
            return 1;

        }
    if(dp[i][lo1][lo2][mask]!= - 1)
        return dp[i][lo1][lo2][mask];

    int lim = (i < N ? lo1 ? 6 : a[i] : lo2 ? 6 : b[i - N] );
    int ans = 0;
    for(int d = 0 ; d <= lim ; d++)
    {
        if( (mask & (1<<d) ) == 0)
            {
                res.push_back(d);
                ans += solve(i + 1, lo1 || (i<N && d < lim) , lo2 || (i > N && d < lim), mask ^ (1<<d));
                res.pop_back();
            }
    }
    return dp[i][lo1][lo2][mask] = ans;
}

int main()
{
    xlr8;
    int testCases  = 1;
    //cin>>testCases;
    while (testCases--)
    {
        cin>>n>>m;
        n--;
        while(n > 0)
            a.push_back(n%7) , n/=7;
        reverse(a.begin() , a.end());
        m--;
        while(m > 0)
            b.push_back(m%7) , m/=7;
        reverse(b.begin() , b.end());
        N = a.size() , M = b.size();
        memset(dp , -1, sizeof(dp));
        cout<<solve(0, 0 , 0,  0);
    }

}

#include<iostream>
#include<stdio.h>
#include<algorithm>

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
int ipow(int n, int k)
{
	int ans=1;
	rep(i,0,k) ans*=n;
	return ans;
}
int main()
{
    int n,m;
	scanf("%d %d\n",&n,&m);
	int kn=0,km=0;
	int nn=n-1,mm=m-1;
	while(nn>0)
	{
		kn++;
		nn/=7;
	}
	while(mm>0)
	{
		km++;
		mm/=7;
	}
	//printf("%d %d\n",kn,km);
	if(kn>6||km>6)
	{
		printf("0\n");
		return 0;
	}
	int ans=0;
	int a[7];
	int ii;
	if(kn+km<=7)
	{
		rep(i,0,ipow(7,kn+km))
		{
			rep(j,0,7) a[j]=0;
			nn = i/ipow(7,km);
			mm = i% (ipow(7,km));
			//printf(" %d %d;",nn,mm);
			ii=i;
			rep(j,0,kn+km)
			{
				if(a[ii%7]==0)
				{
					a[ii%7]++;
					ii/=7;
				}else
				{
					ii=-1;
					break;
				}
			}
			if(ii==(-1) ) continue;
			//printf("%d %d;",nn,mm);

			if(nn<n && mm<m)
			{
				ans++;
				//printf("%d %d;",nn,mm);
			}
		}
	}

	/*
	rep(i,0,ipow(7,kn))
	{
		rep(j,0,7) a[j]=0;
		a[0]=1;
		nn = i;

		//printf(" %d %d;",nn,mm);
		ii=i;
		rep(j,0,kn)
		{
			if(a[ii%7]==0)
			{
				a[ii%7]++;
				ii/=7;
			}else
			{
				ii=-1;
				break;
			}
		}
		if(ii==(-1) ) continue;
		//printf("%d %d;",nn,mm);

		if(nn<n && nn>0 )
		{
			ans++;
			printf("%d %d;",nn,0);
		}
	}

	rep(i,0,ipow(7,km))
	{
		rep(j,0,7) a[j]=0;
		a[0]=1;
		mm = i;
		//printf(" %d %d;",nn,mm);
		ii=i;
		rep(j,0,km)
		{
			if(a[ii%7]==0)
			{
				a[ii%7]++;
				ii/=7;
			}else
			{
				ii=-1;
				break;
			}
		}
		if(ii==(-1) ) continue;
		//printf("%d %d;",nn,mm);

		if( mm<m && mm>0)
		{
			ans++;
			printf("%d %d;",0,mm);
		}
	}
	*/

	//printf("\n");

	printf("%d\n",ans);

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll  x,y,p,q,a,b,n=0,m=0,c=0;cin>>a>>b;
    p=a;q=b;
    while(p){n++; p/=7;}
    while(q){m++; q/=7;}
    if(n+m>7){
        cout<<0<<endl;
        return 0;
    }
    set<ll >s;
    for(ll  i=0; i<a; i++){
        for(ll  j=0; j<b; j++){
             p=i; q=j; x=0; y=0;
             if(p==0) s.insert(0);
             while(p ||x<n){
                s.insert(p%7);
                p/=7;x++;
             }
             if(q==0) s.insert(0);
             while(q && y<m){
                s.insert(q%7);
                q/=7;y++;
             }
             if(s.size()==n+m) c++;
             s.clear();
        }
    }cout<<c<<endl;
}

//xuan

#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <map>
#include <algorithm>

#define fi "c.inp"
#define fo "c.out"
#define ll long long
#define eps 0.0000001
#define tron 1000000007
#define maxint 2147483647
#define pi acos(-1)
#define set(a,b) memset(a,b,sizeof(a))

using namespace std;

int n,m,k,dem,kq;
int a1[110],a2[110];
int dem1,dem2;
int d[10];
int tong;
char s1[110],s2[110];

int kt(int x, int y)
{
	int d1 = dem1;
	int d2 = dem2;

	set(d,0);
	set(s1,0);
	set(s2,0);

	for(int i=0;i<d1;i++)
	{
		s1[i]='0';
	}
	for(int i=0;i<d2;i++)
	{
		s2[i]='0';
	}

	d1--;
	d2--;

	while(x!=0)
	{
		s1[d1]	= (x % 7) + '0';
		d1--;
		x /= 7;
	}
	while(y!=0)
	{
		s2[d2]	= (y % 7) + '0';
		d2--;
		y /= 7;
	}

	for(int i=0;i<dem1;i++)
	{
		for(int j=0;j<dem2;j++)
		{
			if(s1[i] == s2[j]) return 0;
		}
	}
	for(int i=0;i<dem1;i++)
	{
		for(int j=i+1;j<dem1;j++)
		{
			if(s1[i] == s1[j]) return 0;
		}
	}
	for(int i=0;i<dem2;i++)
	{
		for(int j=i+1;j<dem2;j++)
		{
			if(s2[i] == s2[j]) return 0;
		}
	}

	return 1;
}

void solve()
{
	int n0 = n,m0 = m;
	kq = 0;

	dem1 = 0;
	dem2 = 0;

	while(n!=0)
	{
		a1[dem1++] = n%7;
		n = n / 7;
	}
	while(m!=0)
	{
		a2[dem2++] = m%7;
		m = m / 7;
	}

	tong = dem1 + dem2;

	if(tong > 7)
	{
		printf("0\n");
		return;
	}
	else
	{
		for(int i=0;i<n0;i++)
		{
			for(int j=0;j<m0;j++)
			{
				if(kt(i,j)==1) kq++;
			}
		}
	}

	printf("%d\n",kq);
}

int main()
{
	int i,j;
	int t;

//	freopen(fi,"r",stdin);
//	freopen(fo,"w",stdout);

	while(scanf("%d %d",&n,&m)==2)
	{
		solve();
	}

	return 0;
}

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
int maxn=810000;
int a,b,i,j,n,m,k,l,o,p,x[100000],y[100000],tot1,tot2,len[3],num[7],pp[20],ans;
bool check(int x,int id)
{
	memset(pp,0,sizeof (pp));
	int le=1;
	while (x)
	{
		pp[le]=x%7;x/=7;
		le++;
	}
	memset(num,0,sizeof (num));
	for (int i=1;i<=len[id];i++)
	{
		num[pp[i]]++;
		if (num[pp[i]]>=2) return false;
	}
	return true;
}
void get(int x,int id)
{
	int i;long long sum=1,le=0;
	while (sum<=x)
	{
		sum*=7;
		le++;
	}
	len[id]=le;
}
bool ask(int x,int y)
{
	memset(num,0,sizeof num);
	if (x==0&&y==0) return false;
	if (x==0||y==0) num[0]++;
	int len1=0,len2=0;
	 while (x)
	 {
	 	int p=x%7;num[p]++;
	 	if (num[p]>=2) return false;
	 	x/=7;len1++;
	 }
	 if (len1<len[1]) num[0]++;
	 if (num[0]>=2) return false;
	 while (y)
	 {
	 	int p=y%7;num[p]++;
	 	if (num[p]>=2) return false;
	 	y/=7;len2++;
	 }
	 if (len2<len[2]) num[0]++;
	 if (num[0]>=2) return false;
	 return true;
}
int main()
{
	scanf("%d%d",&a,&b);
	if (a>maxn||b>maxn)
	{
		printf("0");
		return 0;
	}
	get(a,1);get(b,2);
    for (i=0;i<a;i++)
    if (check(i,1)) x[++tot1]=i;
    for (i=0;i<b;i++)
    if (check(i,2)) y[++tot2]=i;
    for (i=1;i<=tot1;i++)
     for (j=1;j<=tot2;j++)
      if (ask(x[i],y[j])) ans++;
    printf("%d",ans);
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ff first
#define ss second
#define pp pop_back
#define mp make_pair
#define pb push_back
#define lld long long
#define mid(x, y) (x+y)/2
#define pii pair <int, int>
#define sz(x) (int)x.size()
#define gcd(x, y) __gcd (x, y)
#define all(x) x.begin(), x.end()
#define foreach(i, x) for(auto i: x)
#define lcm(x, y) (x*y) / __gcd (x, y)
#define random srand((unsigned)time(NULL))

using namespace std;
using namespace __gnu_pbds;

template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

///min beryar ---> priority_queue < pii, vector< pii >, greater< pii > > Q;
///max beryar ---> priority_queue < pii > Q;

const int Sq = 317;
const int Base = 27;
const int N = 1e6+6;
const int Max = 1e5+5;
const int Mod = 1e9+7;
const int inf = (1<<31)-1;

int ans;
bool vis[9];
int a[2], len[2];

int no(int x, int y) {
    while(x)
        y++, x/=7;
    return y;
}

void Solution(int pos, int sum, int der, int x) {
    ///cout << pos << ' ' << sum << ' ' << der << ' ' << x << '\n';
    if (sum >= a[x])
        return;

    if (pos > len[x]) {
        if (x == 0)
            Solution(1, 0, 1, 1);
        ///cout << sum << ' ' << x << '\n';
        ans += (x == 1); return;
    }

    for(int i=0; i<7; i++)
        if (!vis[i])
            vis[i]=1, Solution(pos+1, sum+(i*der), der*7, x), vis[i]=0;
}

int main() {
    ///freopen("file.in", "r", stdin);
    ///freopen("file.out", "w", stdout);

    scanf("%d%d", &a[0], &a[1]);

    len[0] = no(a[0]-1, 0);
    len[1] = no(a[1]-1, 0);

    if (len[0]+len[1] <= 7)
        Solution(1, 0, 1, 0);
    printf("%d", ans);
}

#include <bits/stdc++.h>
using namespace std;

int p[10];

int main() {
	int n, m;
	cin >> n >> m;
	p[0]=1;
	for (int i=1; i<=7; i++) p[i]=p[i-1]*7;
	int kn=0, km=0;
	for (int i=7; i>=0; i--) {
		if ((n-1)/p[i]!=0) {
			kn=i+1;
			break;
		}
	}
	for (int i=7; i>=0; i--) {
		if ((m-1)/p[i]!=0) {
			km=i+1;
			break;
		}
	}
	if (kn+km>7) {
		cout << "0\n";
		return 0;
	}
//	cout << kn << " " << km << endl;
	vector <int> v;
	set <pair <int, int> > s;

	for (int i=0; i<7; i++) v.push_back(i);
	do {
		bool was_n=0, was_m=0;
		int nn=0;
		for (int i=0; i<kn; i++) nn+=p[kn-i-1]*v[i], was_n=1;
		int mm=0;
		for (int i=kn; i<kn+km; i++) mm+=p[kn+km-i-1]*v[i], was_m=1;
		if (mm<m && nn<n && was_n && was_m) {
			s.insert({nn, mm});
		}
	}
	while (next_permutation(v.begin(), v.end()));
	cout << s.size() << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int a[10];

int check(int x, int y, int n, int m) {
  memset(a, 0, sizeof a);
  if (!n && !m) return 0;
  while (n) {
    a[x % 7] ++; x /= 7; n /= 7;
  }
  while (m) {
    a[y % 7] ++; y /= 7; m /= 7;
  }
  for (int i = 0; i < 7; i ++) if (a[i] > 1) return 0;
  return 1;
}
int ans = 0;
int main() {
  int n, m;
  cin >> n >> m;
  if (1ll * n * m > 1e7) {
    puts("0"); return 0;
  }
  for (int x = 0; x < n; x ++) {
    for (int y = 0; y < m; y ++) {
      ans += check(x, y, n - 1, m - 1);
    }
  }
  cout << ans << endl;
}

/*
"IF U BELIEVE WHY NOT!!"
                       --Cristiano Ronaldo
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli M=100000000;
#define INF 1000000007
#define bip(n) __builtin_popcount(n)
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
lli n,k,m;
lli z,q,u,l,r,ax,cx,ay,by,cy,ql,qr,d,x,y;
//unordered_map<pair<ll,lli>,lli> mp;
string s;
lli a[500005];
lli vis[500005];
lli me(lli a,lli b,lli M)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    return me((a*a)%M,b/2,M);
    else
    return (a%M*me((a*a)%M,(b-1)/2,M)%M)%M;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
lli pi[400000];
map<lli,lli> ml,ml1;
string pf(string s,lli d)
{
    pi[0]=0;
    for(int j=1;j<s.length();j++)
    {
        int i=pi[j-1];
        if(s[j]!='?')
        {
        while(i>0&&s[j]!=s[i])
        i=pi[i-1];
        }
        else
        {
            while(i>0&&s[i]=='$')
            i=pi[i-1];
            s[j]=s[i];
        }
        if(s[i]==s[j])
        i++;
        pi[j]=i;
    }
    return s;
}
struct edge
{
    lli first,second,third;
}p[400000];
bool cmp(edge a,edge b)
{
    if(a.second==b.second)
    return a.third<b.third;
    return a.second<b.second;
}
set<lli> s2;
lli tot;
lli ccc=0;
lli n1,m1;
void solve(lli n,lli c,lli s,lli s1)
{
    if(n==0)
    {
        if(s2.size()==tot)
        {
            if(s<=n1&&s1<=m1)
            {
                //cout<<s<<" "<<s1<<endl;
                ccc++;
            }
        }
        return;
    }
    if(n>c)
    {
    for(int i=0;i<=6;i++)
    {
     if(s2.count(i))
     continue;
     s2.insert(i);
     solve(n-1,c,(s+i*pow(7,n-c-1)),s1);
     s2.erase(i);
    }
    }
    else
    {
    for(int i=0;i<=6;i++)
    {
     if(s2.count(i))
     continue;
     s2.insert(i);
     solve(n-1,c,s,(s1+i*pow(7,c-1)));
     s2.erase(i);
    }
    }
}
int main()
{
cin>>n>>m;
n1=n-1;
m1=m-1;
lli cnt=0;
lli cnt1=0;
while(n>0)
{
    n=n/7;
    cnt++;
}
while(m>0)
{
    m=m/7;
    cnt1++;
}
//cout<<cnt<<" "<<cnt1<<endl;
if((cnt+cnt1)>7)
return cout<<0,0;
tot=cnt+cnt1;
solve(cnt+cnt1,cnt1,0ll,0ll);
cout<<ccc;
}//

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <numeric>
#include <cmath>

#define ll long long

using namespace std;

bool check(vector<int>& n, vector<int>& limit) {
    bool r = true;
    for (int i = 0; i < n.size(); ++i) {
        if ((i == 0) && (limit[i] == 0)) {
            break;
        }
        if (n[i] > limit[i]) {
            r = false;
            break;
        }
        if ((n[i] == limit[i]) && (i == n.size() - 1)) {
            r = false;
            break;
        }
        if (n[i] < limit[i]) {
            break;
        }
    }
    return r;
}

int main() {
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int n_len = (int)ceil(log(n) / log(7));

    int m_len = (int)ceil(log(m) / log(7));
    n_len = n_len ? n_len : 1;
    m_len = m_len ? m_len : 1;
    if ((n_len + m_len) > 7) {
        cout << "0" << endl;
        return 0;
    }
    vector<int> n_((size_t)n_len);
    vector<int> m_((size_t)m_len);
    for (int i = n_.size()-1; i >= 0; --i) {
        n_[i] = n % 7;
        n /= 7;
    }
    for (int i = m_.size()-1; i >= 0; --i) {
        m_[i] = m % 7;
        m /= 7;
    }
    vector<int> source{0, 1, 2, 3, 4, 5, 6};
    int cnt = 7*6*5*4*3*2*1;
    int ans = 0;
    bool f = false, g = false;
    int i = 0;
    do {
        if (f) {
            int prev = source[n_len + m_len - 1];
            while (i < cnt) {
                next_permutation(source.begin(), source.end());
                ++i;
                if (prev != source[n_len + m_len - 1]) break;
            }
        } else {
            f = true;
        }
        if (i >= cnt) break;
        vector<int> new_n(n_len), new_m(m_len);
        for (int j = 0; j < n_len; ++j) {
            new_n[j] = source[j];
        }
        for (int j = 0; j < m_len; ++j) {
            new_m[j] = source[n_len+j];
        }
        if (check(new_n, n_) && check(new_m, m_)) {
            /*for (int j = 0; j < n_len; ++j) cerr << new_n[j];
            cerr << " ";
            for (int j = 0; j < m_len; ++j) cerr << new_m[j];
            cerr << "\n";*/

            ans++;
        }
    } while (i < cnt);
    cout << ans << "\n";
    return 0;
}

#include <bits/stdc++.h>
#define lll long long
#define pii pair<int,int>
#define pll pair<lll,lll>
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define inf (INT_MAX/2-1)
#define infl (1LL<<61)
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<' '<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<=n;_++) cerr<<x[_]<<" ";cerr<<'\n'; aaa

using namespace std;

int v[7], fv[7];
map<pii,bool> add;

int div7 ( int n )
{
  int i = 0;
  while (n > 0) n /= 7, i++;
  return i;
}

int main ()
{
  int n[2]; cin >> n[0] >> n[1];
  int i, j, z;
  for ( i = 0; i < 7; i++ ) v[i] = i;
  lll ans = 0;
  int nr[2];
  do
  {
    for ( j = 0; j < 7; j++ )
      for ( z = j; z < 7; z++ )
      {
        memset (fv, 0, sizeof fv);
        nr[0] = nr[1] = 0;
        if (j > 1 || (j > 0 && v[0] != 0))
        {
          for ( i = j-1; i >= 0; i-- )
          {
            fv[v[i]]++;
            nr[0] = nr[0] * 7 + v[i];
          }
        }
        if (z > j+1 || (z > j && v[j+1] != 0))
        {
          for ( i = z; i > j; i-- )
          {
            fv[v[i]]++;
            nr[1] = nr[1] * 7 + v[i];
          }
        }
        for ( i = 0; i < 2; i++ )
        {
          if (n[i]-1 == 0 && nr[i] == 0) fv[0]++;
          else fv[0] += (div7(n[i]-1) - div7(nr[i]));
        }
        if ((*max_element(fv, fv+7)) <= 1 && nr[0] < n[0] && nr[1] < n[1] && add[{nr[0],nr[1]}] == 0 )
        {
          add[{nr[0],nr[1]}] = 1;
          ans++;
        }
      }
  }while (next_permutation(v, v+7));
  cout << ans;
  return 0;
}

#include<bits/stdc++.h>
	#define mod 1000000007
	using namespace std;
	typedef long long ll;
	ll power(ll a,ll b)
	{
		ll ans=1;
		while(b)
		{
			if(b&1)
			{
				ans*=a;
				b-=1;
			}
			b/=2;
			a*=a;
		}
		return ans;
	}
	ll gcd(ll n1, ll n2)
	{
	    if (n2!=0)
	       return gcd(n2, n1%n2);
	    else
	       return n1;
	}
	ll arr[100010];
	int main()
	{
		ll n,m,i,j,k;
		cin>>n>>m;
		if(n>=1411788 || m>=1411788)
		{
			cout<<"0"<<endl;
		}
		else
		{

			ll n1=min(n-1,800667LL);
			ll n2=min(m-1,800667LL);
			ll ss1,ss2;
			//if(n-1!=0)
			if(n-1==0)
			{
				ss1=1;
			}
			else
			ss1=ceil(double(log10(double(n-1))/log10(7.0)));
			//else
			//ss1=1;
			//if(m-1!=0)
			if(m-1==0)
			{
				ss2=1;
			}
			else
			ss2=ceil(double(log10(double(m-1))/log10(7.0)));
			//else
			//ss2=1;
			if(pow(7LL,ss1)<=n-1)
			{
				ss1+=1;
			}
			if(pow(7LL,ss2)<=m-1)
			{
				ss2+=1;
			}

			if(m-1==0)
			{
				ss2=1;
			}
		//	cout<<ss1<<" "<<ss2<<endl;
			map<ll,ll>mm,map1,map2;
			map1.clear();
			map2.clear();
			map<ll,ll>::iterator it;
			mm.clear();
			ll b;
			ll flag;
			for(i=0;i<=n1;i++)
			{
				mm.clear();
				ll a=i;
				ll count=0;
				flag=0;
				ll dd=ss1;
				while(dd--)
				{
					b=a%7;
					//cout<<b<<endl;
					if(mm.find(b)!=mm.end())
					{
						flag=1;
						break;
					}
					mm[b]++;
					count+=1;
					a/=7;
				}

				if(flag==1)
				continue;
				//cout<<i<<endl;
				ll val=0;
			//	cout<<"lol "<<mm.size()<<endl;
				for(it=mm.begin();it!=mm.end();it++)
				{
				//	cout<<it->first<<" ";
					val|=(1<<(it->first));
				}
				//cout<<endl;
				map1[val]++;
			}
		//	cout<<"------------------------------------------"<<endl;

		//	cout<<(map1.begin())->first<<endl;
			for(i=0;i<=n2;i++)
			{
				mm.clear();
				ll a=i;
				ll count=0;
				flag=0;
				ll dd=ss2;
				while(dd--)
				{
					b=a%7;
					if(mm.find(b)!=mm.end())
					{
						flag=1;
						break;
					}
					mm[b]++;
					count+=1;
					a/=7;
				}
				if(flag==1)
				continue;
				ll val=0;
				for(it=mm.begin();it!=mm.end();it++)
				{
				//	cout<<it->first<<" ";
					val|=(1<<(it->first));
				}
				//cout<<endl;
				map2[val]++;
			}
			map<ll,ll>::iterator it1,it2;
			ll c,d,a;
			ll sum=0;
			for(it1=map1.begin();it1!=map1.end();it1++)
			{
				a=it1->first;
				b=it1->second;
				for(it2=map2.begin();it2!=map2.end();it2++)
				{
					c=it2->first;
					d=it2->second;
					if(!(a&c))
					{
						//cout<<"ll"<<endl;
						sum+=b*d;
					}
				}
			}
			cout<<sum<<endl;
		}
	}

#include<bits/stdc++.h>
using namespace std;
int n,m;
int dn,dm;
int vis[900000];
int a[8];
int ans;
void dfs(int now)
{
	if(now>dn+dm)
	{
		int sumh=0,x=1;
		for(int i=dn;i>=1;i--)
		{
			sumh+=a[i]*x;
			x*=7;
			if(sumh>n) return ;
		}
		int summ=0,y=1;
		for(int i=dm+dn;i>dn;i--)
		{
			summ+=a[i]*y;
			y*=7;
			if(summ>=m) return ;
		//	printf("%d\n",summ);
		 }
 		ans++;
//	    for(int i=1;i<=dn+dm;i++) printf("%d ",a[i]);
//		printf("\n");
		return ;
	}
	if(now<=dn)
	{
		for(int i=0;i<min(n,7);i++)
		{
			if(vis[i]) continue;
			vis[i]=1;
			a[now]=i;
			dfs(now+1);
			vis[i]=0;
		}
	}
	else
	{
		for(int i=0;i<min(m,7);i++)
		{
			if(vis[i]) continue;
			vis[i]=1;
			a[now]=i;
			dfs(now+1);
			vis[i]=0;
		}
	}
	return ;
}
int main()
{
	scanf("%d%d",&n,&m);
	int N=n;
	while(N)
	{
		N/=7;
		dn++;
	}
	int M=m;
	while(M)
	{
		M/=7;
		dm++;
	}
	if(dn+dm>7)
	{
		printf("%d",0);
		return 0;
	}
	dfs(1);
	printf("%d",ans);
}

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define ff              first
#define ss              second
#define pb(x)           push_back(x)
#define mp              make_pair
#define sz(x)           (int)x.size()
#define mem(x ,y)       memset(x , y , sizeof x )
#define all(a )         a.begin() , a.end()
#define endl            "\n"
#define pii             pair<int,int>
#define clr(x)          x.clear()
#define sl(x )          scanf("%I64d" ,&x)
#define si(x )          scanf("%d" ,&x)
#define forn(i ,x,n )   for(int i = x ; i <= n ; i++ )
#define ford(i ,x,n )   for(int i = x ; i >= n ; i-- )
#define rep(i,n )       for(int i= 0; i<n ; i++ )
#define repit(i, c)     for( __typeof((c).begin()) i = (c).begin(); i != (c).end();++i )

#ifndef ONLINE_JUDGE
    #define dbg(args...)    do {   cout << #args << ' ' ;  print(args); } while(0); cerr<< endl ;
#else
    #define dbg(args...)   ;
#endif

typedef long long ll  ;
typedef unsigned long long ull  ;

ll  mod =  1e9+7, mod2 = 998244353 ;
int setbit(int n, int pos  ) { return n = n|(1LL<< pos) ; }
int resetbit(int n,int pos ) {  return n =  n & ~(1LL<<pos ); }
bool checkbit(int  n,int pos ) { return (bool ) (n&(1LL<<pos))  ; }
template<typename T> void print(const T& v) {    cerr << v << ' ' ;}
template<typename T>T add(T x, T y, T mod = mod ){ x%= mod ;  y%= mod ;   return (x+y)%mod ;  }
template<typename T>T sub(T x, T y, T mod = mod ){ return ((x-y)%mod+mod )%mod;  }
template<typename T>T mul(T x, T y, T mod = mod ){ x %= mod ; y %= mod ; return (x*y)%mod  ;  }
template<typename T1,typename... T2> void print( const T1& first, const T2&... rest ){ print(first); print(rest...) ;}
template<typename T> void dbg_a(T a[] ,int n=10 ) {cerr << "[ "; for(int i=0;i <= n ; i++ )cerr<<a[i]<<' ' ; cerr<< " ]" <<  endl; }
template<typename F,typename S>ostream& operator<<( ostream& os, const pair< F, S > & p ){return os << "[ " << p.first << ", " << p.second << " ]";}
template<typename T>ostream &operator<<(ostream & os, const vector< T > &v ){os << "[ "; for(int i=0; i<sz(v) ; i++ )  os << v[i] << ' ' ; return os << " ]\n" ; }
template<typename T>ostream &operator<<(ostream & os, const map< T ,T> &Map ){os << "[ "; repit(it , Map ) os << "[" <<(*it).ff << ' ' << (*it).ss << "] "    ; return os << "]\n" ; }
template<typename T>ostream &operator<<(ostream & os, const set< T > &Set  ){os << "[ "; repit(it , Set ) os <<  *it  << ' ' ; return os << " ]\n" ; }
template<typename T>ostream &operator<<(ostream & os, const multiset< T > &Set) {os << "[ "; repit(it , Set )os <<  *it  << ' ' ; return os << " ]\n" ; }
template<class T> string to_str(T t){stringstream ss; ss<<t; return ss.str();}
// typedef tree<  int    ,     // change type
//               null_type,
//               less_equal  < int  >  ,  // change type ..
//               rb_tree_tag,
//               tree_order_statistics_node_update> ordered_set;
template < typename T >
T  bigmod(T x, T k ,T mod = mod) {
    if(k == 0 ) return (T)1;
    if(k&1  ) {
        return ( (x%mod)*bigmod(x,k-1, mod )%mod )%mod ;
    } else {
        T ret = bigmod(x,k/2  , mod ) ;
        ret %= mod ;
        return (ret*ret )%mod;
    }
}
template < typename T >
T  invmod( T x , T m) {
    return bigmod(x,m-2 , m) ;

}
#define  int  ll
const int maxn  = (int)1e6+123 ;
const ll inf  =  1e18 ; //  0xc0  ; //0x3f ; //
/////////////////////////////////////////////////////

int a[maxn ] ,b[maxn ] , n ,  m  ;
int dp[2][10][(1<<10)+12] ;

int func(int id , int mask ,int  f )  {
    if(id>=  n+m) {
        return 1 ;
    }
    int &ans =  dp[f][id ][mask ] , lo , hi   ;
    if(  ans!=-1)  return ans ;

    if(id>=n ) f=0 ;

    lo = 0 ;
    if(f==1 ) hi  = 6 ;
    else hi  =  a[id ] ;

    ans = 0  ;
    if(f) {
        forn(i , lo  ,hi)  {
            if(checkbit(mask,i ) )  continue ;
            ans += func( id+1  , setbit(mask ,i) ,f ) ;

        }
    }  else{

        forn(i , lo  ,hi-1)  {
            if(checkbit(mask,i ) )  continue ;
            ans += func( id+1  , setbit(mask ,i) ,1  ) ;

        }

        if(checkbit(mask ,hi) ==0)  {
            ans += func( id+1  , setbit(mask , 0 ) , 0   ) ;

        }

    }

    return ans ;
}
void  solve() {
    int  x,y,z ,ans=0,  f= 0  , cnt = 0 , mx  = 0   ;

    cin  >> n >> m ;
    n-- ;
    m-- ;
    int _n  = n  , _m =  m ;

    vector<int> v ;

    while( n) {
        v.pb(n%7)  ;
        n/=7 ;

    }
    reverse(all( v) ) ;
    rep(i,sz(v )  ) a[i] =v[i] ;

    if(_n==0) n=1 ;
    else  n = sz( v)  ;

    v.clear()  ;

    while( m) {
        v.pb(m%7)  ;
        m/=7 ;

    }
    reverse(all( v) ) ;
    rep(i,sz(v )  ) a[i+n] =v[i] ;

    if(_m==0) m =1 ;
    else  m  = sz( v)  ;

    mem(dp  , -1)  ;
    cout <<  func(0  , 0 , 0) << endl ;

}
signed main() {
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
          // freopen("out.txt", "w", stdout) ;
    #endif
    ios :: sync_with_stdio(false);  cin.tie(0);  cout.tie(0) ;
    // clock_t st = clock()  ;
    // cout << fixed << setprecision(12) ;
    int  c = 0 ,t = 1  ;
    // cin  >>t ;
    while(t--) {
        solve() ;
    }
    //cerr<<"Execution time : " << (double)(clock()-st )/CLOCKS_PER_SEC << endl ;

    return 0 ;
}

//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + '0');
    putchar('\n');
}

const LL mod=1e9+7;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=(1<<18)+10;
const int maxn=1005;

LL n,m,ans=0;
int a[20],b[20],cnt1=0,cnt2=0,vis[10];
LL fn,fm;
LL p[19];

void DFS2(int po,LL num)
{
    if(po>cnt2)
    {
        if(num<fm)ans++;
        return ;
    }
    for(int i=0;i<7;i++)
    {
        if(!vis[i])
        {
            vis[i]=1;
            DFS2(po+1,num+(LL)i*p[po]);
            vis[i]=0;
        }
    }

}

void DFS1(int po,LL num)
{
    if(po>cnt1)
    {
        if(num<fn){DFS2(1,0);}
        return ;
    }
    for(int i=0;i<7;i++)
    {
        if(!vis[i])
        {
            vis[i]=1;
            DFS1(po+1,num+(LL)i*p[po]);
            vis[i]=0;
        }
    }
}

int main()
{
            read(n);read(m);
            fn=n,fm=m;
            LL w=1;
            for(int i=1;i<=9;i++)
            {
                p[i]=w;
                w=w*7;
            }
            while(n)
            {
                a[++cnt1]=n%7;
                n/=7;
            }
            while(m)
            {
                b[++cnt2]=m%7;
                m/=7;
            }
            DFS1(1,0);
            cout<<ans<<"\n";

        return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define MAXN (int)2e5+5
#define f first
#define vs s.size()-1
#define sd second
typedef long long int llf;
llf INF=100000000000LL;
typedef pair<int,int> pp;
typedef pair<int,pp> ppp;
int used[7];
llf n,m;
int main(){
    //freopen("input.txt", "r", stdin);
	  //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    n--,m--;
    llf x=0,y=0,a=n,b=m;
    while(a){
      x++;a/=7;
    }
    while(b){
      y++;b/=7;
    }
    //cout<<x<<" "<<y<<endl;
    if(x+y>7){
      cout<<0<<endl;
      return 0;
    }
    llf ans=0;
    for(llf i=0;i<=n;i++){
      for(llf j=0;j<=m;j++){
        a=i,b=j;
        memset(used,0,sizeof(used));
        bool ok=true;
        for(int k=0;k<x;k++){
          if(used[a%7LL]){
            ok=false;
            break;
          }
          used[a%7LL]=1;
          a/=7;
        }
        for(int k=0;k<y;k++){
          if(used[b%7LL]){
            ok=false;
            break;
          }
          used[b%7LL]=1;
          b/=7;
        }
        if(ok) ans++;
      }
    }
    cout<<ans<<endl;
    return 0;
}

#include <iostream> // standard input & output cout cin
#include <cstdio> // scanf printfsssss
#include <vector> // std::vector
#include <algorithm>
#include <string> // std::string
#include <queue> // std::queue
#include <cstring> // memset
#include <set> // std::set
#include <utility> // std::pair, std::make_pair
#include <map>
#include <list>
#include <stack>
#include <deque>
#include <cmath>
#include <ctime>
#include <chrono>

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const char newline = '\n';

const int dy[4] = {-1,0,0,1};
const int dx[4] = {0,-1,1,0};
#define pb(x) push_back(x)
#define forn(i,n) for(int i = 0 ; i < int(n); ++i)

int n,m;
VI v = {0,1,2,3,4,5,6};
set<pair<int, int> > abc;
int answer;

int main(int argc, char **argv)
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	int a,b; // 시침과 분침의 자리수

	if(n == 1)
	{
		a = 1;
	}
	else
	{
		a = log(n-1)/log(7) + 1;
	}

	if(m == 1)
	{
		b = 1;
	}
	else
	{
		b = log(m-1)/log(7) + 1;
	}

	//cout<<a<<' '<<b<<newline;
	int digit = a+b; // 시계의 자리수
//
	if(digit > 7)
	{
		answer = 0;
	}
	else
	{
		do
		{
			int v1,v2;
			v1 = v2 = 0;
			for(int i = 0 ; i < a; i++)
			{
				v1 *= 7;
				v1 += v[i];
			}

			for(int j = a ; j < a+b ;j++)
			{
				v2 *= 7;
				v2 += v[j];
			}

			if(v1 < n && v2 < m)
			{
				if( abc.find(make_pair(v1, v2)) != abc.end())  // 발견
				{
					// do nothing
				}
				else
				{
					abc.insert(make_pair(v1,v2));
		/*
					for(int i = 0 ; i < a; i++) cout<<v[i];
					cout<<' ';
					for(int j =a; j< a+b ; j++) cout<<v[j];
					cout<<' ';
					cout<<v1 << ' ' <<v2<<newline;
		*/
					answer++;
				}
			}
		} while ( next_permutation(v.begin(), v.end()));
	}
	cout<<answer<<newline;
  return 0;
}

#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

set<string> bio;
long long res = 0;
long long n,m;
long long prve_cifre = 0, druge_cifre = 0;
long long prva_potencija, druga_potencija;

bool validna(string s)
{
	long long prvi = 0, drugi = 0, temp = prva_potencija, indeks = 0;
	while(temp)
	{
		prvi += (s[indeks]-'0') * temp;
		temp /= 7;
		indeks++;
	}
	temp = druga_potencija;
	while(temp)
	{
		drugi += (s[indeks]-'0') * temp;
		indeks++;
		temp/=7;
	}
	if(prvi<=n and drugi<=m)return true;
	else return false;
}

void provjeri(string s)
{

	sort(s.begin(),s.end());
	if(bio.find(s)==bio.end())
	{
		//cout << "na provjeri je string: " << s << endl;
		bio.insert(s);
		if(validna(s))res++;
	//	if(validna(s))cout << "ovaj je dobar: " << s << endl;
		while(next_permutation(s.begin(),s.end()))
			if(validna(s))
			{
				res++;
			//	cout << "ovaj je dobar: " << s << endl;
			}
	}
}

void rek(int ostalo,string trenutni)
{
	if(!ostalo)
	{
		provjeri(trenutni);
		return ;
	}
	bool ima[10] = {0,0,0,0,0,0,0,0,0,0};
	for(int i=0;i<trenutni.size();i++)
		ima[trenutni[i]-'0'] = true;

	for(int i=0;i<7;i++)
		if(!ima[i])
		rek(ostalo-1,trenutni+char('0'+i));
}

int main()
{
	cin >> n >> m;
	prva_potencija = druga_potencija = 1;
	long long temp = n;
	n--, m--, temp = n;
	while(n)
	{
		prve_cifre++;
		prva_potencija*=7;
		n/=7;
	}
	n = temp, temp = m;
	while(m)
	{
		druge_cifre++;
		druga_potencija*=7;
		m/=7;
	}
	m = temp;
	prva_potencija /= 7, druga_potencija /= 7;

	if(prve_cifre+druge_cifre>7)cout << 0 << endl;
	else
	{
		//cout << "upao u rekurziju" << endl;
		rek(prve_cifre+druge_cifre,"");
		cout << res << endl;
	}
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair <int,int> pii;

#define trace(x) cout << #x << "  " << x << endl
#define fors(i, a, b) for (int i = (a); i < int(b); i++)
#define rep(i, n) fors(i, 0, n)
int rjes;
ll n,m,br1,br2,pot[110],cd,bio[200];

ll cnt(ll x){
	ll y = 0;
	while(x != 0){
		x /= 10;
		y++;
	}

	return y;
}

ll pret(ll x){
	ll z = 0;
	int flag = 0;
	for(int y = 8;y >= 0;y--){
		if(x / pot[y] != 0){
			flag = 1;

			z += x /pot[y];

			x = x % pot[y];

		}
		if(flag&&y != 0){
			z *= 10;
		}
	}

	return z;
}

int main(){

	scanf("%lld %lld",&n,&m);
	pot[0] = 1;
	fors(i,1,23){
		pot[i] = pot[i - 1] * 7;
	}
	//printf("bio %lld\n",pret(n));
	br1 = cnt(pret(n - 1));
	br2 = cnt(pret(m - 1));
	//printf("bio %lld %lld %lld %lld\n",br1,br2,pot[br1],pot[br2]);
	if(br1 + br2 > 7){
		printf("0");

	}
	else{

		rep(i,pot[br1]){
			rep(j,pot[br2]){
				rep(k,11){
					bio[k] = 0;
				}
				cd = 0;
				//printf("bio1 %d %d\n",i,j);
				if(i < n&&j < m){

					if((br1 + br2)- (cnt(pret(i)) + cnt(pret(j))) > 1){

						continue;
					}
					else if((br1 + br2)- (cnt(pret(i)) + cnt(pret(j))) == 1){
						bio[0]++;

					}
					ll di = pret(i);
					ll dj = pret(j);
					//printf("bio2 %d %d\n",i,j);
					while(di != 0){
						bio[di % 10]++;
						if(bio[di % 10] > 1){
							cd = 1;
						}

						di /= 10;
					}

					while(dj != 0){
						bio[dj % 10]++;
						if(bio[dj % 10] > 1){
							cd = 1;
						}

						dj /= 10;
					}

					if(!cd){

						rjes++;
						//printf("%d\n",rjes);
					}
				}
			}
		}
		printf("%d\n",rjes);
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

string toSeven(const int& x, const int& maxs){
	string s;
	int p = maxs;
	int u = 7;
	int xx = x;
	while(p){
		s += xx % 7 + '0';
		xx /= 7;
		p /= 7;
	}
	reverse(s.begin(), s.end());
	return s;
}

int main() {
	int n, m; cin >> n >> m;

	int sizes = toSeven(n, n - 1).size() + toSeven(m, m - 1).size();

	if(sizes > 7){
		cout << 0 << endl;
		return 0;
	}
	long long count = 0;

	for(int i = 0; i < n; ++i){
		for(int j = 0; j < m; ++j){
			set<char> ss;
			string s = toSeven(j, m - 1);
			//cout << s << ' ';
			for(int t = 0; t < s.size(); ++t)
				ss.insert(s[t]);

			//string g = s;
			s = toSeven(i, n - 1);
			//cout << s << endl;;
			for(int t = 0; t < s.size(); ++t)
				ss.insert(s[t]);
			if(ss.size() == sizes){
				//cout << g + s << endl;
				++count;
			}
		}
	}
	cout << count << endl;
}

#include <bits/stdc++.h>

using namespace std;
long long n, m, gg, nn, mm, likk,tt, zn, b,  a[10], p, dl1, dl2, lik1, lik2, kol;
set < string > d;
set < string > ::iterator pos;
char g;
string sn, np, sn1;
int main()
{
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);

    cin >> n >> m;
    nn = n;
    mm = m;
    zn = 0;
    while (nn!=0){
        b = nn %7;
        dl1++;
        nn = nn / 7;
    }
    while (mm!=0){
        b = mm %7;
        dl2++;
        mm = mm / 7;
    }
kol=0;
    for (int i = 0; i <= 6; i++)
        a[i] = i;

    p = 5040;

    for (int i = 1; i <= p; i++){
            sn="";
    sn1="";
    for (int j = 0; j < dl1; j++){
        g = a[j]+'0';
        sn=sn+g;

    }
    for (int j = dl1; j < dl1+dl2; j++){
        g = a[j]+'0';
        sn1=sn1+g;

    }
   // cout << sn<< " " << sn1<<endl;
    likk=0;
        for (int j = 0; j < sn.size(); j++){
            gg = int(sn[j])-'0';
            likk=likk*10+gg;
        }
    lik1=0;
        for (int j = 0; j < sn1.size(); j++){
            gg = int(sn1[j])-'0';
            lik1=lik1*10+gg;
        }
if (likk<n&&lik1<m){

    if (d.find(sn+sn1)!=d.end()){
        tt++;} else {
            d.insert(sn+sn1);
            //cout << likk<<"  "<< lik1<<endl;
            kol++;
            }

    }

next_permutation(a,a+7);
}

cout << kol << endl;

    return 0;
}

#include <iostream>
using namespace std;
int n, m, len1, len2, res, used[7];
bool flag;
int len(int n) {
	int l = 1;
	while (n > 0) {
		n /= 7;
		l++;
	}
	return l;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(); cout.tie();
	cin >> n >> m;
	len1 = len(n - 1); len2 = len(m - 1);
	if (len1 + len2 > 7) {
		cout << 0; return 0;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			for (int ii = 0; ii < 7; ii++) used[ii] = 0;
			for (int ii = 0, a = i; ii < len1; ii++, a /= 7) used[a % 7]++;
			for (int jj = 0, b = j; jj < len2; jj++, b /= 7) used[b % 7]++;
			flag = true;
			for (int ii = 0; ii < 7; ii++) if (used[ii] > 1) { flag = false; break; }
			if (flag) res++;
		}
	}
	cout << res;
	return 0;
}

/*
ye mera template hai
apna khud likho bc :P
*/

/*
Author : Sarvagya Agarwal
*/

#include<bits/stdc++.h>
using namespace std;

//defines
#define openin freopen("input.txt","r",stdin)
#define openout freopen("output.txt","w",stdout)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
//#define int long long
#define mod 1000000007
#define rep(i,a,n) for(__typeof(n) i=a;i<=n;++i)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

//templates
template <typename T>T expo(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=(x*p)%m;p=(p*p)%m;n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}
template <typename T> T gcd(T a, T b){while(a%=b^=a^=b^=a); return b;}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

//debug
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

// DOBARA OVERFLOW KI GALTI HUI TO TU CHUTIYA HAI BC
// update : TU CHUTIYA HAI BC
int arr[10];
int ans=0,leftt,n,m,rightt;
int num(int l,int r)
{
    int res = 0 , base = 1;
    for(int i=r;i>=l;i--)
    {
        res += base*arr[i];
        base*=7;
    }
    return res;
}
void solve(int index,int prev)
{
    //trace(index,prev);
    if(index>leftt+rightt)
    {
        int LEFT = num(1,leftt);
        int RIGHT = num(leftt+1,leftt+rightt);
        //trace(LEFT,RIGHT);
        if(LEFT < n && RIGHT < m)
        {
            // check now
            int cnt[8]={0};
            rep(i,1,leftt+rightt)cnt[arr[i]]++;
            bool yes = true;
            rep(i,0,6)if(cnt[i]>1)yes=false;
            if(yes)
            {
             //   trace(LEFT,RIGHT);
                ans++;
            }
        }
        return ;
    }
    rep(i,0,6)
    {
        if(i==prev)continue;
        arr[index] = i;
        solve(index+1,i);
    }
    return ;
}
int main()
{
    fast;
    cin>>n>>m;
    int temp = n;
    while(temp)
    {
        leftt++;
        temp/=7;
    }
    temp = m ;
    while(temp)
    {
        rightt++;
        temp/=7;
    }
    //trace(leftt,rightt);
    if(leftt+rightt>7)
    {
        cout<<0;
        return 0;
    }
    solve(1,-1);
    cout << ans;
    return 0;
}

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
const int mod = 1e9+7;
const int maxn = 2e5+7;

int n,m;
int d[20];
int ans = 0;
int v[10];
ll a,b,k;
int w1,w2;
void dfs(int x,int w){
    if(w==0){
        k = 1;
        a=b=0;
        for(int i=w1-1;i>=0;i--){
            a += k*d[i];
            k *= 7;
        }
        k = 1;
        for(int i=1;i<=w2;i++){
            b += k*d[w1+w2-i];
            k *= 7;
        }
        if(a<n&&b<m){
            ans++;
        }
    }
    else{
        for(int i=0;i<7;i++){
            if(v[i]==0){
                v[i] =  1;
                d[x] = i;
                dfs(x+1,w-1);
                v[i] = 0;
            }
        }
    }
}
int main(){
    cin >> n >> m;
    ll t = 1;
    for(w1=1;;w1++){
        t = t*7;
        if(t-1>=n+1){
            break;
        }
    }
    t = 1;
    for(w2=1;;w2++){
        t = t*7;
        if(t-1>=m+1){
            break;
        }
    }
    if(w1+w2>7){
        cout<<0;return 0;
    }
    dfs(0,w1+w2);
    cout<<ans;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define ft first
#define sc second
#define pb push_back
#define fastIO ios::sync_with_stdio(0);
#define files(i,o) freopen(i,"r",stdin); freopen(o,"w",stdout);

int cnt(ll x){
  if(x==0 || x==1){
    return 1;
  }
  int i=0;
  for(;x>=1;x/=7)i++;
  return i;
}
int dn,dm;
int a[7];
int check(int x,int y){
  if(x==y){
    return 0;
  }
  memset(a,0,sizeof(a));

  if(cnt(x) < dn || cnt(y) < dm){
    a[0]=1;
  }
  if(x==0){
    a[x%7]++;
    if(a[x%7]>1){
      return 0;
    }
  }
  if(y==0){
    a[y%7]++;
    if(a[y%7]>1){
      return 0;
    }
  }
  for(;x>=1;x/=7){
    a[x%7]++;
    if(a[x%7]>1){
      return 0;
    }
  }

  for(;y>=1;y/=7){
    a[y%7]++;
    if(a[y%7]>1){
      return 0;
    }
  }
  return 1;
}
int main(){
  /// freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  int n,m,ans=0;
  cin >> n >> m;
  dn = cnt(n);
  dm = cnt(m);
  ll sw = 7*7*7*7*7;
  for(int i=0;i<n && cnt(i)<823543;i++){
    for(int j=0;j<m && cnt(i)+cnt(j)<=7;j++){
      if( check(i,j) ){
        ans++;
      }
    }
  }
  cout << ans;
}

/**
*
*/
#include <bits/stdc++.h>
#define MAXN 5000
#define INF 2000000000
#define _INF -20000000

typedef long long ll;
using namespace std;

const ll mod = 1e9 + 7;

struct p {
    int u, v, w;
    p() {}
    p(int u, int v, int w) : u(u), v(v), w(w) {}
    bool operator<(const p &right) {
        return this->u < right.u;
    }
};

int len(ll n) {
    int res = 0;
    while(n) {
        res += 1;
        n /= 7;
    }
    return res;
}

int used[10];
int a = 0, b = 0;
ll ans = 0;
ll x, y, xz = 0;

ll pw(int b) {
    ll res = 1;
    for(int i = 0; i < b; ++i) res *= 7;
    return res;
}

void g(int k, int z, ll t) {
    t += pw(b - k - 1) * z;

    if(k == b - 1) {

        if(t < y) {
            xz += 1;

        }

        return;

    }

    used[z] = 1;

    for(int i = 0; i < 7; ++i) {
        if(!used[i]) {
            g(k + 1, i, t);
        }
    }

    used[z] = 0;

    return;

}

void f(int k, int z, ll t) {
    t += pw(a - k - 1) * z;
    if(k == a - 1) {

       used[z] = 1;

       if(t < x ) {
            for(int i = 0; i < 7; ++i) {
                if(!used[i]) {
                    xz = 0;
                    g(0, i, 0);
                    ans += xz;
                }
            }

       }
       used[z] = 0;
       return;

    }

    used[z] = 1;

    for(int i = 0; i < 7; ++i) {
        if(!used[i]) {

            f(k + 1, i, t);

        }
    }

    used[z] = 0;

}

int main() {
    // input
    cin >> x >> y;

    a = len(x), b = len(y);

    if(a + b > 7) {
        cout << 0 << endl;
        return 0;
    }

    for(int i = 0; i < 7; ++i) {

        f(0, i, 0);

    }

    cout << ans << endl;

}

#include <bits/stdc++.h>

#define size(n) ( int( n.size() ) )
#define sqr(n) ( (n) * (n) )
#define pb push_back
#define mp make_pair

using namespace std;

long long ans = 0;

int n, m, cnt[256], f[256];

int main(){
    //freopen("input.txt","r",stdin);
    scanf("%d %d\n",&n,&m);
    int i, j, curr, currCnt, maxM = 0, maxN = 0, mask, tmp;
    for ( i = 0; i < 256; i++ ){
        cnt[i] = 0;
        f[i] = 0;
    }
    tmp = m - 1;
    while( tmp != 0 ){
        tmp /= 7;
        maxM++;
    }
    maxM = max( maxM, 1 );
    tmp = n;
    while( tmp != 0 ){
        tmp /= 7;
        maxN++;
    }
    maxN = max( maxN, 1 );
    for ( j = 0; j <= min( m - 1, 900000 ); j++ ){
        tmp = j;
        mask = 0;
        currCnt = 0;
        while( tmp != 0 ){
            curr = tmp % 7;
            if ( ( ( mask >> curr ) & 1 ) == 1 ){
                break;
            }
            mask += ( 1 << curr );
            tmp /= 7;
            currCnt++;
        }
        currCnt = max( currCnt, 1 );
        if ( ( tmp != 0 ) || ( maxM - currCnt >= 2 ) ){
            continue;
        }
        if ( maxM - currCnt == 1 ){
            if ( mask % 2 == 1 ){
                continue;
            }
            mask++;
        }
        cnt[mask]++;
    }
    int k;
    for ( i = 0; i < 256; i++ ){
        for ( j = 0; j < 256; j++ ){
            for ( k = 6; k >= 0; k-- ){
                if ( ( ( ( i >> k ) & 1 ) != ( ( j >> k ) & 1 ) ) && ( ( ( i >> k ) & 1 ) == 0 ) ){
                    break;
                }
            }
            if ( k < 0 ){
                f[i] += cnt[j];
            }
        }
    }
    for ( i = 0; i <= min( n - 1, 900000 ); i++ ){
        mask = 0;
        tmp = i;
        currCnt = 0;
        while( tmp != 0 ){
            curr = tmp % 7;
            if ( ( ( mask >> curr ) & 1 ) == 1 ){
                break;
            }
            mask += ( 1 << curr );
            tmp /= 7;
            currCnt++;
        }
        currCnt = max( currCnt, 1 );
        if ( ( tmp != 0 ) || ( maxN - currCnt >= 2 ) ){
            continue;
        }
        if ( maxN - currCnt == 1 ){
            if ( mask % 2 == 1 ){
                continue;
            }
            mask++;
        }
        ans += f[ ( 1 << 7 ) - 1 - mask ];
    }
    printf("%I64d",ans);
    return 0;
}

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <cctype>
#include <utility>
#include <queue>
#include <cmath>
#include <complex>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef double DB;

#define pb push_back
#define mset(a, b) memset(a, b, sizeof a)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#define X first
#define Y second

#define Error(x) cout << #x << " = " << x << endl

template <typename T, typename U>
inline void chkmax(T& x, U y) {
	if (x < y) x = y;
}

template <typename T, typename U>
inline void chkmin(T& x, U y) {
	if (y < x) x = y;
}

int cnt[1000000];
int a[1000000];

void solve(int n) {
	VI d;
	int x = n;
	while (x > 0) {
		d.push_back(x % 7);
		x /= 7;
	}
	reverse(all(d));
	int sz = min(sz(d), 7);
	int tot = 1;
	for (int i = 1; i <= sz; i++) {
		tot *= 7;
	}
	for (int i = 0; i < tot && i < n; i++) {
		int s = 0, flg = 1;
		for (int j = 0, k = i; j < sz; j++) {
			int l = k % 7;
			if (s & bit(l)) {
				flg = 0;
				break;
			}
			s |= bit(l);
			k /= 7;
		}
		if (flg) {
			cnt[s]++;
		}
	}
}

int main() {

	int n, m; cin >> n >> m;
	solve(n);
	for (int i = 0; i < bit(7); i++) {
		a[i] = cnt[i];
	}
	memset(cnt, 0, sizeof cnt);
	solve(m);
	long long ans = 0;
	for (int i = 0; i < bit(7); i++) {
		for (int j = 0; j < bit(7); j++) {
			if (i & j) {
				continue;
			}
			ans += (LL)a[i] * cnt[j];
		}
	}
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int base7(int i){
	if(i == 0) return 0;
	return base7(i/7) + 1;
}

int main(){
  std::ios::sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  #endif

	int n,m,ln,lm;
	cin >> n >> m;
	ln = base7(n-1);
	lm = base7(m-1);
	if(ln + lm > 7){
		cout << 0 << endl;
		return 0;
	}
	cout << ln << " " << lm << endl;
	int res = 0;
	for(int i=0;i<m;++i){
		set<int> s;
		int cur = i;
		bool ok = true;
		int val = 0;
		for(int j=0;j<lm;++j){
			if(s.find((cur%7)) != s.end()) ok = false;
			s.insert((cur%7));
			cur /= 7;
		}
		if(!ok) continue;
		for(int k=0;k<n;++k){
			set<int> ss = s;
			cur = k;
			val = 0;
			ok = true;
			for(int j=0;j<ln;++j){
				if(ss.find((cur%7)) != ss.end()) ok = false;
				ss.insert((cur%7));
				cur /= 7;
			}
			if(!ok) continue;
			++res;
		}
	}

	cout << res << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;
long long n, m, gg, nn, mm, likk,tt, zn, b,  a[100], p, dl1, dl2, lik1, lik2, kol, dd;
set < string > d;
set < string > ::iterator pos;
char g;
string sn, np, sn1;
int main()
{
    //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);

    cin >> n >> m;
     if (n==m) {cout << 0 << endl; return 0;}
    nn = n;    mm = m;    zn = 0;

    while (nn!=0){ b = nn %7; dl1++;    nn = nn / 7; }

    while (mm!=0){ b = mm %7; dl2++;     mm = mm / 7;}

    //if (dl1+dl2>7) { cout<<0<<endl; return 0;}
    kol=0;

    for (int i = 0; i <= 6; i++)  a[i] = i;

    for (int i = 1; i <= 5040; i++){
    sn=""; sn1="";

    for (int j = 0; j < dl1; j++){ g = a[j]+'0'; sn=sn+g;}

    for (int j = dl1; j < dl1+dl2-1; j++){ g = a[j]+'0'; sn1=sn1+g;}

    likk=0;
    for (int j = 0; j < sn.size(); j++){ dd= int(sn[j])-'0';likk=likk*7+dd;}

    lik1=0;
    for (int j = 0; j < sn1.size(); j++){ gg = int(sn1[j])-'0'; lik1=lik1*7+gg;}

string st = "";

    st = sn + sn1;
    //cout <<st <<endl;

    //cout << likk<<"  "<< lik1<<endl;

//cout << sn<<"  "<< sn1<<endl;
    if (likk<n&&lik1<m){  d.insert(st);  }

next_permutation(a,a+7);
}

cout << d.size() << endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n, m;
int n1, n2, res, nr, mr;

vector <int> digit[2], ans;

bool check[7], ok;

long long power[8] = {1, 7, 49, 343, 2401, 16807, 117649, 823543};

int dp(int pos, bool bound, int type)
{
    int np = pos + 1, nt = type;
    bool nb = false; int ret = 0;
    if (pos > n1 + n2)
    {
        if (nr < n && mr < m)
        {
            return 1;
        }
        else return 0;
    }
    int tmp = pos, limit = 6;
    if (type == 1) tmp -= n1;
    //if (bound == true) limit = digit[type][tmp-1];
    for (int i = 0; i <= limit; ++i)
    {
        if (!check[i])
        {
            check[i] = true; ans.push_back(i);
            if (pos <= n1) nr += i * power[n1 - pos];
            else mr += i * power[n2 - tmp];//nl = i;
            //if (np == n1 + n2 + 1) ok = true;
            if (i == limit) nb = true;
            if (pos == n1)
            {
                nt = 1; nb = true;
            }
            ret += dp(np, nb, nt); check[i] = false;
            if (pos <= n1) nr -= i * power[n1 - pos];
            else mr -= i * power[n2 - tmp];
            ans.pop_back();
        }
    }
    return ret;
}

void tach(int x, int type)
{
    while (x > 0)
    {
        digit[type].push_back(x % 7);
        x = x / 7;
    }
    reverse(digit[type].begin(), digit[type].end());
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m; //ok = false;
    tach(n - 1, 0); tach(m - 1, 1);
    n1 = digit[0].size(); n2 = digit[1].size();
    if(!n1)++n1; if(!n2)++n2;
    if (n1 + n2 > 7) cout << 0 << endl;
    int res = dp(1, true, 0);
    //if (!ok) res--;
    cout << res << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int n, m;
int a, b, vis[10], mod, ans;

void doit(int d, int res) {
	if(d == a + b) {
		int x = res / mod;
		int y = res % mod;
		if(x < n && y < m) ans ++;
		return ;
	}
	for(int i = 0; i < 7; i ++) if(!vis[i]) {
		vis[i] = 1;
		doit(d + 1, res * 7 + i);
		vis[i] = 0;
	}
}

int run() {
	if(a + b > 7) return 0;
	mod = 1;
	for(int i = 0; i < b; i ++) mod *= 7;
	doit(0, 0);
	return ans;
}

int main() {
	scanf("%d%d", &n, &m);
	int x = n - 1;
	while(x) {
		x /= 7; a ++;
	}
	x = m - 1;
	while(x) {
		x /= 7; b ++;
	}
	printf("%d\n", run());
	return 0;
}

#include <iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
const int maxn=1000;
#define ll __int64
int vis[11];
ll cnt,n,m;
void dfs(ll n1,ll m1,ll x1,ll x2)
{
    if(x1<0||x2<0||n1>=n||m1>=m) return ;
    if(x1==0&&x2==0)
    {
      //  cout<<"####"<<n1<<"####"<<m1<<endl;
       cnt++;
       return ;
    }
    for(int i=0;i<=6;i++)
    {
        if(!vis[i])
        {
            vis[i]=1;
            dfs(n1*10+i,m1,x1-1,x2);
            if(x1==0)
            dfs(n1,m1*10+i,x1,x2-1);
            vis[i]=0;
        }
    }
}
int main()
{
    ll x1,x2,nn,mm,p,n2,m2;
    memset(vis,0,sizeof(vis));
    cnt=0;
    p=1;
    scanf("%I64d%I64d",&n,&m);
    n2=n,m2=m;
    nn=mm=0;
    x1=x2=0;
    while(n2)
    {
        nn=(n2%7)*p+nn;
        n2=n2/7;
        p=p*10;
        x1++;
    }
    p=1;
      while(m2)
    {
        mm=(m2%7)*p+mm;
        m2=m2/7;
        p=p*10;
        x2++;
    }
   // cout<<nn<<"  "<<mm<<endl;
    //cout<<x1<<"  "<<x2<<endl;
    if(x1+x2>7)
    {
        printf("0\n");
    }
    else{
        dfs(0,0,x1,x2);
        printf("%I64d\n",cnt);
    }
}

#include <bits/stdc++.h>
using namespace std;
#define ri(x) scanf("%d",&x)
#define FOR(i,j,k) for(int i = j; i<k; i++)
#define ms(obj,val) memset(obj,val,sizeof(obj))
typedef long long ll;
bool used[7];
ll ans = 0;
int main(){
	int N,M;
	cin >> N >> M;
	int digitsN=(N==0),digitsM=(M==0);
	for(int i = 1; i<N; i*=7) digitsN++;
	for(int i = 1; i<M; i*=7) digitsM++;
	//cout << digitsN << " " << digitsM << endl;
	if(digitsM + digitsN > 7) {printf("0\n");return 0;}
	for(int i = 0; i<N; i++){
		for(int j = 0; j<M; j++){
			ms(used,false);
			bool valid = true;
			int cnt = 0;
			for(int k = i;cnt<digitsN;cnt++){
				if(used[k%7]){valid = false;break;}
				used[k%7] = true;
				k/=7;
			}
			if(!valid) continue;
			cnt = 0;
			for(int k = j; cnt<digitsM; cnt++){
				if(used[k%7]){valid = false;break;}
				used[k%7] = true;
				k/=7;
			}
			if(!valid) continue;
			ans++;
		}
	}
	cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
int getnum(int a)
{
    int res=0;
    while(a)
    {
        a/=7;
        res++;
    }
    return res;
}
int a[10];
int acnt;
int last;
int n,m;
long long dp[10][(1<<7)];
long long dfs(int d,int state,bool lead,bool limit)
{
    if(d==0)return 1;
    if(!limit&&!lead&&dp[d][state]!=-1)return dp[d][state];
    long long ans=0;
    int up;
    if(limit)
    {
        up=a[d];
    }
    else
    {
        if(d>last)
        {
            up=min(6,n-1);
        }
        else
        {
            up=min(6,m-1);
        }
    }
    for(int i=0;i<=up;i++)if(((state>>i)&1)==0)
    {
        ans+=(dfs(d-1,state+(1<<i),lead&&i==0,limit&&i==a[d]));
    }
    if(!limit&&!lead)dp[d][state]=ans;
    return ans;

}

int main()
{
    memset(dp,-1,sizeof(dp));

    scanf("%d %d",&n,&m);
    int ncnt=getnum(n);
    int mcnt=getnum(m);
    if(ncnt+mcnt>7)
    {
        cout<<0<<endl;
        return 0;
    }
    last=0;
    int mm=m-1;
    //if(mm==0)a[++acnt]=0;
    while(mm)
    {
        a[++acnt]=mm%7;
        mm/=7;
        last++;
    }
    int nn=n-1;
    //if(nn==0)a[++acnt]=0;
    while(nn)
    {
        a[++acnt]=nn%7;
        nn/=7;
    }
    printf("%lld\n",dfs(acnt,0,1,1));
    return 0;
}

#include<bits/stdc++.h>

#define pb push_back
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;

const int N = (int)1e5 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;

int n, m, ans;
vector<int> n7, m7;
bool u[7];
int a[111];

void rec(int num, int pos) {
	//cout << pos << " " << num << endl;
	if(pos == sz(n7) + sz(m7)) {
		ans ++;
		return;
	}
	u[num] = 1;
	a[pos] = num;
	if(pos == 0) {
		for(int i = 0; i <= n7[0]; i ++)
			rec(i, pos + 1);
	}else if(pos == sz(n7) ) {
		for(int i = 0; i <= m7[0]; i ++)
			if(!u[i])
				rec(i, pos + 1);
	} else {
		int gr = 6, bg = 0;
		if(pos < sz(n7)) {
			if(a[1] == 0)
				for(int i = 1; i < 7; i ++)
					if(u[i])
						bg = 1;
			if(a[1] == n7[0])
				gr = n7[pos - 1];
		}
		else {
			if(a[sz(n7) + 1] == 0)
				for(int i = 1; i < 7; i ++)
					if(u[i])
						bg = 1;
			if(a[sz(n7) + 1] == m7[0])
				gr = m7[pos - 1];
		}
		for(int i = bg; i <= gr; i ++)
			if(!u[i])
				rec(i, pos + 1);
	}
	u[num] = 0;
}

int main() {
	cin >> n >> m;
	n --, m --;
	while(n > 0) {
		n7.pb(n % 7);
		n /= 7;
	}
	reverse(n7.begin(), n7.end());
	while(m > 0) {
		m7.pb(m % 7);
		m /= 7;
	}
	reverse(m7.begin(), m7.end());
	if(sz(n7) + sz(m7) > 7) {
		cout << 0;
		return 0;
	}
	rec(0, 0);
	cout << ans;
	return 0;
}

#include<bits/stdc++.h>

#define mp make_pair
#define vi vector<int>
#define xx first
#define yy second
#define all(a) a.begin(), a.end()
#define vsort(v) sort(all(v))
#define UNIQUE(a)  sort(all(a)); a.erase(unique(all(a)), a.end())
#define clr(a,k) memset(a,k,sizeof a)
#define bclr(b) memset(b,false,sizeof b)
#define fr(i, a) for(i = 0; i < a; i++)
#define frr(i,a) for(i = a - 1; i >= 0, i--)
#define LL long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vll vector<long long>
///***** bit *****///
#define check_bit(a, b) (a&(1<<b))
#define set_bit(a, b) (a|(1<<b))
#define total_bit(a) __builtin_popcount(a)

#define WRITE freopen("A_large.txt","w",stdout)
#define use_cin  ios_base::sync_with_stdio(0); cin.tie(0);
#define READ  freopen("a2.in","r",stdin)

///***** Input / Output *****///
#define s1(a) scanf("%d", &a)
#define s2(a, b) scanf("%d %d", &a, &b)
#define s3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define s4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define p1(a) printf("%d", a)
#define p2(a, b) printf("%d %d", a, b)
#define p3(a, b, c) printf("%d %d %d", a, b, c)
#define eps 1e-9
#define deb cout<<"I am here"<<endl
#define MOD 1000000007
#define MAX (lim+7)
#define INF 100000000
#define PI acos(-1.0)

using namespace std;

///******* Template ********///

template <class T> inline T bigmod(T p,T e,T M)
{
    if(e==0)return 1;
    if(e%2==0)
    {
        T t=bigmod(p,e/2,M);
        return (t*t)%M;
    }
    return (bigmod(p,e-1,M)*p)%M;
}
template <class T> inline T gcd(T a,T b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

/**
return (a * b) % m;
where a, b, m <= 10^18
**/
template <class T> inline T multimod(T a, T b, T m)
{
    T ans = 0ll;
    a%=m, b%=m;
    while(b)
    {
        if(b&1ll) ans = m - ans > a?(ans + a): (ans + a - m);
        b >>= 1ll;
        a = (m - a)>a?a+a:a+a-m;
    }
    return (T)ans;
}

///****** fast scan ends here ***********///

//int dr[] = {-1, 0, 1, 0};
//int dc[] = {0, 1, 0, -1}; /// 4 sides
//int dr[] = {-1, -1, 0, 1, 1, 1, 0, -1}; dc[] = {0, 1, 1, 1, 0, -1, -1, -1}; /// 8 sides

#define LEN(a) strlen(a)

#define MX 1000000000000000000ll
#define lim 100000      /// 10^5

///***** Template ends here *****///
///********************* Code starts here ****************************

int num[MAX];

vector<int>V;

int power[20];
int main()
{
//    READ;
//    WRITE;
    int i, j, k, K;
    int x;
    power[0] = 1;
    for(i = 1;i <= 10; i++)
        power[i] = power[i-1]*7;
    int n, m;
    s2(n, m);
    int nn = 0, nm = 0;
    int sn = n, sm = m;

    while(n)
    {
        nn++;
        n = n/7;
    }
    while(m)
    {
        nm++;
        m = m/7;
    }
//    cout<<nn<<" "<<nm<<endl;
    if((nn + nm) > 8)
    {
//        assert(0);
        printf("%d\n", 0);
        return 0;
    }
    for(i = 0; i < 7; i++)
        V.pb(i);
    int cnt = 0, ss = 0;
    map< pii, bool>M;
    do
    {
        int fst = 0, snd = 0;
        for(i = nn-1; i >= 0; i--)
            fst = fst + V[i]*power[nn-1-i];

        for(i = nn+nm-1; i >= nn; i--)
            snd = snd + V[i]*power[nn+nm-1-i];
        if(fst <= sn && snd <= sm && M.find(mp(fst, snd)) == M.end())
        {

            if(fst == 0)
            {
                for(i = nn+nm-1; i >= nn; i--)
                    if(fst == V[i]) goto XX;
            }
            if(snd == 0)
            {
                for(i = nn-1; i >= 0; i--)
                    if(snd == V[i]) goto XX;
            }

            cnt++;
            M[ mp(fst, snd) ] = 1;
//            cout<<fst<<" " <<snd<<endl;
        }
        XX:
            {

            }
    }
    while(next_permutation(V.begin(), V.end()));

    printf("%d\n", cnt);

    return 0;
}

/*

*/

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define endl '\n'

using namespace std;

typedef long long int ll;
typedef unsigned long long int llu;

ll n, m;
ll ans;

string transform(int i){
	string ret = "";
	while(i/7 > 0){
		ret += char((i%7)+'0');
		i/=7;
	}
	ret += char((i)+'0');
	return ret;
}

int main (){

	cin >> n >> m;

	if(n+m > 200){
		cout << 0 << endl;
		return 0;
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			string s = transform(i);
			int sz = s.size();
			if(sz < ceil(n*1.0/7.0)){
				reverse(s.begin(),s.end());
				for(int k = 0; k < abs(sz-ceil(n*1.0/7.0)); k++){
					s+='0';
				}
				reverse(s.begin(),s.end());
			}
			string s1 = transform(j);
			sz = s1.size();
			if(sz < ceil(m*1.0/7.0)){
				reverse(s1.begin(),s1.end());
				for(int k = 0; k < abs(sz-ceil(m*1.0/7.0)); k++){
					s1+='0';
				}
				reverse(s1.begin(),s1.end());
			}
			s = s + s1;
			bool ok = true;
			int x = 0;
			//cout << s << endl;
			for(int k = 0; k < s.size(); k++){
				if(!(1<<(s[k]-'0')&x)){
					x = x|(1<<(s[k]-'0'));
				}
				else{
					ok = false;
				}
			}
			if(ok)
				//cout << s << endl;
			ans += ok;
		}

	}
	cout << ans << endl;

	return 0;
}

///----------------------------Template-----------------------///

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define fi first
#define prev asfansjfansjabfasjlbfa
#define se second
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define out_files freopen("ladder.in", "r", stdin);freopen("ladder.out", "w", stdout)
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(0)
#define y1 asnflainflawnfaw
#define y0 snalfklawnfasdaspqw

using namespace std;

typedef vector <int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef vector <pii> vii;
typedef long double ld;

#ifdef WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif // WIN32

const int inf = 1000000000;
const ll INF = 1LL*inf*inf;
const double eps = 1e-9;
const int MAXN = 2500;
const int md = (int)1e9 + 7;
const double EPS = 1e-5;
const ll maxll = numeric_limits<ll>::max();

template <typename name> inline name sqr(name x)
{
    return x*x;
}

template <typename name> inline name bpow(name base, ll exp, ll md = maxll)
{
    if (exp == 0) return 1;
    if (exp % 2 == 1)
        return (base * bpow(base, exp-1, md)) % md;
    else
    {
        name k = bpow(base, exp/2, md);
        return (k*k)%md;
    }
}

///-------------------------End of Template-------------------------///

int n, m, ans1, ans2, use[11];
ll step[40], res;
vi roz;

void check(int x)
{
    int flag = 0;
    for (int i=0; i<10; i++)
        use[i] = 0;
    int it = 0;
    int x1 = x;
    if (x == 0) use[0] = 1, it++;
    while (x)
    {
        use[x%7] += 1;
        x /= 7;
        it++;
    }
    if (it < ans1)
    {
        it++;
        use[0]++;
    }
    if (it < ans1)
        use[0]++;
    if (flag) return;
    for (int i=0; i<m; i++)
    {
        int q = i, iter = 0, flag = 0;
        if (q == 0) use[0]++, iter++;
        while (q)
        {
            use[q%7] ++;
            q /= 7;
            iter++;
        }
        if (iter < ans2)
        {
            use[0]++;
            iter++;
        }
        if (iter < ans2)
            use[0]++;
        for (int j=0; j<10; j++)
            if (use[j] > 1) flag = 1;
        if (!flag) res++;
        q = i;
        iter = 0;
        if (q == 0) use[0]--, iter++;
        while (q)
        {
            use[q%7]--;
            q /= 7;
            iter++;
        }
        if (iter < ans2)
        {
            use[0]--;
            iter++;
        }
        if (iter < ans2)
            use[0]--;
    }
}

int main()
{
    scanf(II, &n, &m);
    if (n>m) swap(n,m);
    ans1 = 1;
    ans2 = 1;
    step[0] = 1;
    for (int i=1; i<12; i++)
    {
        step[i] = step[i-1]*7;
        if (m>=step[i]) ans2++;
        if (n>=step[i]) ans1++;
    }
    if (ans1 + ans2 > 7) return cout << 0, 0;
    for (int i=0; i<n; i++)
    {
        check(i);
    }
    cout << res;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int findlog(int n)
{
    int ans=0;
    int power=1;
    while(power<=n)
    {
        power*=7;
        ans++;
    }
    return ans;
}
string m1(int num, int a)
{
    string ans;
    while(num)
    {
        int w=num%7;
        num/=7;
        ans=char(w+'0')+ans;
    }
    int l=ans.length();
    while(l<a)
    {
        ans='0'+ans;
        l++;
    }
    return ans;
}
bool checkall(string a,string b)
{
    unordered_set<char> w;
    for(int i=0;i<a.length();i++)
    {
        if(w.find(a[i])!=w.end())
            return false;
        w.insert(a[i]);
    }
    for(int i=0;i<b.length();i++)
    {
        if(w.find(b[i])!=w.end())
            return false;
        w.insert(b[i]);
    }
    return true;
}
int main()
{
	int n,m;
	cin>>n>>m;
	int a=findlog(n);
	int b=findlog(m);
	if(a+b>7)
        cout<<0<<endl;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            string str=m1(i,a);
            string str1=m1(j,b);
            //cout<<str<<"    "<<str1<<endl;
            //cout<<a<<"   "<<b<<endl;
            if(checkall(str,str1))
                ans++;
        }
    }
    cout<<ans<<endl;
    //int z;cin>>z;
 	return 0;
}

#include<bits/stdc++.h>

#define fname ""
#define pb push_back
#define mp make_pair
#define ss second
#define ff first

using namespace std;

typedef long long ll;
const int maxn = (1e5) + 10;
const int INF = (1e9);
const ll inf = (1e18);
const double eps = (1e-9);

ll n, m, p[10000], r;
bool us[10];
int cnt;
ll ans[10000], t, tt;
void dfs(int cur, bool us[10], ll ho, ll mi) {
	if(ho < 1 || mi < 1)
		return;
	if(cur == t + 1) {
		r++;
		return;
	}
	for(ll i = 0; i <= 6; ++i) {
		if(!us[i] && ans[cur] >= i) {
			if((cur <= tt && i*p[tt-cur] < ho)) {
			//	cout << "zdes " << i << endl;
				us[i] = 1;
				dfs(cur + 1, us, ho - i*p[tt-cur], mi);
				us[i] = 0;
		 	}
		 	if(cur > tt & i*p[t-tt-cur+1] < mi) {
		 	//	cout << "zdes2 " << i << endl << mi - i*p[cur-tt-1] << endl;
				us[i] = 1;
				dfs(cur + 1, us, ho, mi - i*p[t-tt-cur+1]);
				us[i] = 0;
			}
		}
	}
	return;
}
int main() {

	ios_base::sync_with_stdio(false);
    cin.tie(0);
//	#ifdef LOCAL
//	freopen(fname".in", "r", stdin);
//	freopen(fname".out", "w", stdout);
//	#endif

	p[0] = 1;
	cin >> n >> m;
	for(cnt = 1;;++cnt) {
		p[cnt] = p[cnt - 1] * 7;
		if(p[cnt] > INF) {
			break;
		}
	}
//	cout << cnt << "\n";
	for(int i = cnt; i >= 0; --i) {
		if(n / p[i] != 0) {
			ans[++t] = min((n / p[i]), 6ll);
		}
	}
	tt = t;
	for(int i = cnt; i >= 0; --i) {
		if(m / p[i] != 0) {
			ans[++t] = min((m / p[i]), 6ll);
		}
	}
//	cout << tt << " " << t << "\n";
//	for(int i = 1; i <= t; ++i)
//		cout << ans[i] << "\n";
	dfs(1, us, n, m);
	cout << r;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,m;
int dn,dm;
int vis[900000];
int a[8];
int ans;
void dfs(int now)
{
	if(now>dn+dm)
	{
	    for(int i=1;i<=dn+dm;i++) printf("%d ",a[i]);
		printf("\n");
		int sumh=0,x=1;
		for(int i=dn;i>=1;i--)
		{
			sumh+=a[i]*x;
			x*=7;
			if(sumh>n) return ;
		}
		int summ=0,y=1;
		for(int i=dm+dn;i>dn;i--)
		{
			summ+=a[i]*y;
			y*=7;
			if(summ>=m) return ;
		//	printf("%d\n",summ);
		 }
 		ans++;
		return ;
	}
	if(now<=dn)
	{
		for(int i=0;i<min(n,7);i++)
		{
			if(vis[i]) continue;
			vis[i]=1;
			a[now]=i;
			dfs(now+1);
			vis[i]=0;
		}
	}
	else
	{
		for(int i=0;i<min(m,7);i++)
		{
			if(vis[i]) continue;
			vis[i]=1;
			a[now]=i;
			dfs(now+1);
			vis[i]=0;
		}
	}
	return ;
}
int main()
{
	scanf("%d%d",&n,&m);
	int N=n;
	while(N)
	{
		N/=7;
		dn++;
	}
	int M=m;
	M--;
	while(M)
	{
		M/=7;
		dm++;
	}
	if(dn+dm>7)
	{
		printf("%d",0);
		return 0;
	}
	dfs(1);
	printf("%d",ans);
}

#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <set>

using namespace std;

int ans = 0;

bool iter(vector<int>& v)
{
    for (int t = v.size() - 1; t >=0; t--)
    {
        v[t]++;
        if (v[t] > 6)
        {
            v[t] = 0;
        }
        else
        {
            break;
        }
    }
    return true;
}

void check(const vector<int>& v1, const vector<int>& v2)
{
    vector<int> v;
    for (auto elem : v1)
        v.push_back(elem);
    for (auto elem : v2)
        v.push_back(elem);

    set<int>s;
//    for (auto elem : v)
//        cout << elem;
//    cout << endl;
    for (auto elem : v)
        s.insert(elem);
    if (s.size() == v.size())
        ans++;

}

int main()
{
    int h = 0, m = 0, i_h, i_m;
    cin >> i_h >> i_m;
    int c_h = i_h;
    int c_m = i_m;
    while (i_h > 0)
    {
        i_h /= 7;
        h++;
    }

    while (i_m > 0)
    {
        i_m /= 7;
        m++;
    }
    if (h + m > 7)
    {
        cout << 0;
        return 0;
    }

    vector<int>v_h(h,0);
    vector<int>v_m(m,0);
    for (int i = 0; i < c_h ; i++)
    {
        for (int j = 0; j < c_m; j++)
        {
            check(v_h, v_m);
            iter(v_m);
        }
        for (int i = 0; i < v_m.size(); i++)
            v_m[i] = 0;

        iter(v_h);
    }
    cout << ans;
}

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int len,w,g[20],p[10000],n,m,len1,len2;
long long Ans;
int digit[2010],f[2010],h[3010];
int dfs1(int x) {
	len = 0;w = 1;
	while(x > 0)
	{
		g[ ++len] = p[(x & (-x))];
		x -= (x & (-x));w *= len;
	}
	if(len != len1) return 0;
	int Ret = 0;
	long long ret = 0,base = 1;
	for(int i = 1;i <= w;i ++)
	{
		ret = 0;base = 1;
		for(int j = 1;j <= len;j ++)
		{
			ret += 1ll * g[j] * base;
			base *= 7ll;
		}
		if(ret < 1ll * n) Ret ++;
		next_permutation(g + 1,g + len + 1);
	}
	return Ret;
}
int dfs2(int x) {
	len = 0;w = 1;
	while(x > 0)
	{
		g[ ++len] = p[(x & (-x))];
		x -= (x & (-x));w *= len;
	}
	if(len != len2) return 0;
	int Ret = 0;
	long long ret = 0,base = 1;
	for(int i = 1;i <= w;i ++)
	{
		for(int j = 1;j <= len;j ++)
		{
			ret += 1ll * g[j] * base;
			base *= 7ll;
		}
		if(ret < 1ll * m) Ret ++;
		next_permutation(g + 1,g + len + 1);
	}
	return Ret;
}
int main() {
	scanf("%d%d",&n,&m);
	for(int i = 0;i <= 6;i ++)
		p[1 << i] = i;
	int x = n;
	while(x > 0) len1 ++,x /= 7;
	x = m;
	while(x > 0) len2 ++,x /= 7;
	for(int i = 1;i <= (1 << 7) - 2;i ++)
	{
		x = i;
		while(x > 0) x -= (x & (-x)),digit[i] ++;
	}
	for(int i = 1;i <= (1 << 7) - 2;i ++)
		if(digit[i] == len1)
			f[i] = dfs1(i);
	for(int i = 1;i <= (1 << 7) - 2;i ++)
		if(digit[i] == len2)
			h[i] = dfs2(i);
	for(int i = 1;i <= (1 << 7) - 2;i ++)
		for(int j = 1;j <= (1 << 7) - 2;j ++)
			if((!(i &j)) && digit[i] == len1 && digit[j] == len2)
				{Ans += 1ll * f[i] * h[j];}
	//cout<<f[1]<<' '<<f[2]<<' '<<f[4]<<' '<<h[1]<<' '<<h[2]<<' '<<h[4]<<endl;
	cout<<Ans;
}

#include <ctime>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <stack>
#include <utility>
#include <queue>
#include <list>

#define PI 3.14159265

using namespace std;

int count_digits(int n)
{
  int res = n % 7 == 0 ? 0 : 1;
  while ( n > 7 )
  {
    n = n/7;
    res++;
  }
  if (n == 7) res++;
  return res;
}

void print_vec(vector<int>& v)
{
  for (int i = 0; i < v.size(); ++i)
    cout << v[i] <<" ; ";
  cout << endl;
}

bool unique(vector<int>& digits)
{
  for (int i = 0; i < digits.size(); ++i)
    if (digits[i] > 1) return false;
  return true;
}

int main(int argc, const char *argv[])
{
  ios::sync_with_stdio(false);
  int n,m;
  cin >> n >> m;
  int digits_n = count_digits(n);
  int digits_m = count_digits(m);
//  cout << "digits_n : " << digits_n << endl;
  //cout << "digits_m : " << digits_m << endl;
  if (digits_n + digits_m > 7)
    cout << 0 << endl;
  else
  {
    long long res = 0;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j)
      {
        vector<int> digits(7,0);
        int a = i;
        int k = 0;
        while(k < digits_n )
        {
          digits[a % 7]++; a /= 7; k++;
        }
        a = j; k = 0;
        while ( k < digits_m )
        {
          digits[a % 7]++; a /= 7; k++;
        }
        if (unique(digits))
        {
//          print_vec(digits);
          res++;
        }
      }
    cout << res << endl;
  }
  return 0;
}

#include <stdio.h>

long long n, m;
int nc, mc;
int c;
int cn[9], cm[9], ck[9];

void call(long long v1, long long v2, int l1, int l2) {
	for (int i = 0; i < 7; i++) {
		ck[i] = 0;
	}

	bool flag = true;

	for (int i = l1; i >= 1; i--) {
		long long div = v1 % 7;
		ck[div]++;
		if (ck[div] == 2) {
			flag = false;
		}
		v1 /= 7;
	}
	for (int i = l2; i >= 1; i--) {
		long long div = v2 % 7;
		ck[div]++;
		if (ck[div] == 2) {
			flag = false;
		}
		v2 /= 7;
	}
	if (flag) {
		c++;
	}
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%I64d %I64d", &n, &m);

	long long b = 1;
	for (int i = 1; i <= 22; i++) {
		if (b <= n && n < b * 7) {
			nc = i;
		}
		if (b <= m && m < b * 7) {
			mc = i;
		}

		b = b * 7;
	}

	if (nc + mc > 7) {
		printf("0\n");
		return 0;
	}

	for (long long i = 0; i < n; i++) {
		for (long long j = 0; j < m; j++) {
			call(i, j, nc, mc);
		}
	}

	printf("%d\n", c);

	return 0;
}

#include <iostream>

using namespace std;
long long n,m,l1,l2;
string n1,m1;
bool kt[20];

string str(int s)
{
    string ans="";
    while (s)
    {
        ans=(char)(s%7+'0')+ans;
        s/=7;
    }
    return ans;
}

long long dp(int vt,bool kt1,bool kt2)
{
    if (vt>n1.length()+m1.length())
    {
        return 1;
    }
    long long ans=0;
    if (vt>=n1.length()+1)
    {
        {
            if (kt2)
            {
                for (int i=0;i<=6;++i)
                    if (!kt[i])
                    {
                        kt[i]=true;
                        ans+=dp(vt+1,kt1,kt2);
                        kt[i]=false;
                    }
            }
            else
            {
                for (int i=0;i<m1[vt-n1.length()-1]-'0';++i)
                if (!kt[i])
                {
                    kt[i]=true;
                    ans+=dp(vt+1,kt1,true);
                    kt[i]=false;
                }
                if (!kt[m1[vt-n1.length()-1]-'0'])
                {
                    kt[m1[vt-n1.length()-1]-'0']=true;
                    ans+=dp(vt+1,kt1,kt2);
                    kt[m1[vt-n1.length()-1]-'0']=false;
                }
            }
        }
    }
    else
    {
        if (kt1)
            {
                for (int i=0;i<=6;++i)
                    if (!kt[i])
                    {
                        kt[i]=true;
                        ans+=dp(vt+1,kt1,kt2);
                        kt[i]=false;
                    }
            }
            else
            {
                for (int i=0;i<n1[vt-1]-'0';++i)
                if (!kt[i])
                {
                    kt[i]=true;
                    ans+=dp(vt+1,true,kt2);
                    kt[i]=false;
                }
                if (!kt[n1[vt-1]-'0'])
                {
                    kt[n1[vt-1]-'0']=true;
                    ans+=dp(vt+1,kt1,kt2);
                    kt[n1[vt-1]-'0']=false;
                }
            }
    }
    return ans;
}

int main()
{
    cin>>n>>m;
    --n;
    --m;
    n1=str(n);
    m1=str(m);
    l1=n1.length();
    l2=m1.length();
    cout<<dp(1,0,0);
    return 0;
}

#include<iostream>
#include<cstdio>
using namespace std;
typedef __int64 ll;
ll m,n;
ll pow(ll x)
{
    if(x==0) return 1;
    return 10*pow(x-1);
}
ll f(ll x)
{
    ll res=0,tmp=1;
    while((tmp-1)<x)
    {
        tmp*=7;
        res++;
    }
    return res;
}
bool check(ll t)
{
    ll x=t;
    ll a=f(m);ll b=f(n);
    ll num1=0,num2=0,cnt[8];
    for(int i=0;i<8;i++) cnt[i]=0;
    ll t1=1,t2=1;
    for(ll i=1;i<=b;i++)
    {
        ll tmp = x%10;
        if(tmp>=7) return 0;
        cnt[tmp]++;
        tmp*=t1;
        t1*=10;
        num1+=tmp;
        x/=10;
    }
    for(ll i=1;i<=a;i++)
    {
        ll tmp = x%10;
        if(tmp>=7) return 0;
        cnt[tmp]++;
        tmp*=t2;
        t2*=10;
        num2+=tmp;
        x/=10;
    }
    if(num1>=n) return 0;
    if(num2>=m) return 0;
    for(int i=0;i<=6;i++)
    {
        if(cnt[i]>=2) return 0;
    }
    return 1;
}
int main()
{
    cin>>m>>n;
    if(f(m)+f(n)>7)
    {
        cout<<0<<endl;
    }else{
        ll ans=0;
        for(ll i=0;i<pow(f(m)+f(n));i++)
        {
            if(check(i)){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

bool vis[7];
int num[2][66];
int len[2];

bool same(int a,int b)
{
    //printf("%d %d\n",a,b);
    memset(vis,0,sizeof(vis));
    int x = 0;
    while(a)
    {
        if(vis[a%7]) return true;
        vis[a%7] = 1;
        a /= 7;
        x++;
    }
    if(x < len[0])
    {
        if(vis[0]) return true;
        vis[0] = 1;
    }

    x = 0;
    while(b)
    {
        if(vis[b%7]) return true;
        vis[b%7] = 1;
        b /= 7;
        x++;
    }
    if(x < len[1]) if(vis[0]) return true;
    //puts("*****");
    return false;
}

int le(int a)
{
    int x = 0;
    while(a)
    {
        a /= 7;
        x++;
    }
    return x;
}

int main()
{
    int n,m;
    int a,b;

    scanf("%d%d",&n,&m);
    a = n;
    b = m;

    len[0] = len[1] = 0;

    while(n)
    {
        num[0][len[0]++] = n%7;
        n /= 7;
    }

    while(m)
    {
        num[1][len[1]++] = m%7;
        m /= 7;
    }

    if(len[0]+len[1] > 7)
    {
        puts("0");
        return 0;
    }

    int ans = 0;
    int st1,st2;
    st1 = st2 = 0;

    while(len[0]-le(st1) > 1) st1++;
    while(len[1]-le(st2) > 1) st2++;

    for(int i = st1; i < a; ++i)
        for(int j = st2; j < b; ++j)
        {
            if(!same(i,j)) ans++;
        }

    printf("%d\n",ans);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,m,A,B,cnt;
int Ans;
int Pow[7];
int vis[7];
inline void DFS(int M,int N,int d)
{
    if(d>=A && M>=m)return ;
    else if(d>=cnt)
    {
        if(N<n && (N+M))Ans++;
        return;
    }
    for(int i=0;i<7;i++)
    {
        if(vis[i])continue;
        vis[i]=1;
        if(d<A)DFS(M+i*Pow[d],N,d+1);
        else DFS(M,N+i*Pow[d-A],d+1);
        vis[i]=0;
    }
}
int main()
{
    //freopen("data.in","r",stdin);
    int tmp;
    scanf("%d%d",&n,&m);
    tmp=1;
    while(tmp<m)tmp*=7,A++;
    tmp=1;
    while(tmp<n)tmp*=7,B++;
    cnt=A+B;
    Pow[0]=1;
    for(int i=1;i<7;i++)Pow[i]=Pow[i-1]*7;
    if(cnt<=9)DFS(0,0,0);
    printf("%d\n",Ans);
}

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p%=m;
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const ll mod = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

int32_t main(){
    IOS;

    int n,m;
    cin>>n>>m;
    int l1=0,l2=0;
    int tmp1=1,tmp2=1;
    while(tmp1<n){
    	tmp1*=7;
    	l1++;
    }
    while(tmp2<m){
    	tmp2*=7;
    	l2++;
    }

    cerr<<l1<<l2<<endl;
    if(l1+l2>7){

    	cout<<0<<endl;
    	return 0;
    }
    int ans=0;
    for(int i=0;i<n;i++){
    	for(int j=0;j<m;j++){
    		vector<int> cnt(7,0);
    		int t1 = i,t2 = j;
    		for(int in=0;in<l1;t1/=7,in++){
    			cnt[t1%7]++;
    		}
    		for(int in=0;in<l2;t2/=7,in++){
    			cnt[t2%7]++;
    		}
    		int mx=0;
    		for(int i=0;i<7;i++)
    			mx = max(mx,cnt[i]);
    		if(mx<2){
    			// cout<<i<<" "<<j<<endl;
    			ans++;
    		}
    	}
    }
    cout<<ans<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define LL long long
int n,m,lc1,lc2;
LL sum,cc[110],cc1[110],c1[110],c2[110];
bool vv[15];
void dfs2(int len)
{
    int tot=0,k=1;
    if(len==lc2+1)
    {
        for(int i=lc2;i>=1;i--)
        {
            tot+=k*cc1[i];
            k*=7;
        }
        if(tot>=m)return;
        //for(int i=1;i<=lc1;i++)printf("%d ",cc[i]);
        //for(int i=1;i<=lc2;i++)printf("%d ",cc1[i]);
        //printf("\n");
        sum++;
        return;
    }
    for(int i=0;i<=6;i++)if(vv[i]==false){vv[i]=true;cc1[len]=i;dfs2(len+1);cc1[len]=0;vv[i]=false;}
}
void dfs(int len)
{
    int tot=0,k=1;
    if(len==lc1+1)
    {
        for(int i=lc1;i>=1;i--)
        {
            tot+=k*cc[i];
            k*=7;
        }
        if(tot>=n)return;
        memset(cc1,0,sizeof(cc1));
        dfs2(1);
        return;
    }
    for(int i=0;i<=6;i++)if(vv[i]==false){vv[i]=true;cc[len]=i;dfs(len+1);cc[len]=0;vv[i]=false;}
}
int main()
{
    int nn,mm;
    scanf("%d %d",&n,&m);
    //if(n==1&&m==1){printf("0");return 0;}
    nn=n;mm=m;
    lc1=0;
    while(nn>0)
    {
        c1[++lc1]=nn%7;
        nn/=7;
    }
    lc2=0;
    while(mm>0)
    {
        c2[++lc2]=mm%7;
        mm/=7;
    }
    if(n==7)lc1--;
    if(m==7)lc2--;
    //n--;m--;
    if(lc1+lc2>7){printf("0");return 0;}
    sum=0LL;
    memset(cc,0,sizeof(cc));
    memset(vv,false,sizeof(vv));
    dfs(1);
    //if(n-1==0||m-1==0)sum--;
    printf("%lld",sum);
    fclose(stdin);
    fclose(stdout);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int vis[7];
int n, m;

bool check(int h, int min){
	memset(vis, 0, sizeof(vis));
	int num1 = (n == 1 ? 1 : (int)(log(n)/log(7)) + 1);
	int num2 = (m == 1 ? 1 : (int)(log(m)/log(7)) + 1);
	for(int i = 0; i < num1; i++){
		if(h == 0)vis[0]++;
		else{
			vis[h%7]++;
			h /= 7;
		}
	}
	for(int i = 0; i < num2; i++){
		if(min == 0)vis[0]++;
		else{
			vis[min%7]++;
			min /= 7;
		}
	}
	for(int i = 0; i < 7; i++){
		if(vis[i] > 1)return false;
	}
	return true;
}

int main(){
	//int n, m;
	scanf("%d%d", &n, &m);
	int num1 = (n == 1 ? 1 : (int)(log(n)/log(7)) + 1);
	int num2 = (m == 1 ? 1 : (int)(log(m)/log(7)) + 1);
	//printf("%d,%d\n", num1, num2);
	//check(312, 9);
	if(num1+num2 > 7){
		printf("0\n");
	}else{
		int ans = 0;
		for(int i = 0; i <= n-1; i++){
			for(int j = 0; j <= m-1; j++){
				if(check(i, j)){
					ans++;
					//if(i == 319 && j == 9){
					//for(int i = 0; i < 7; i++){
					//	printf("%d %d\n", i, vis[i]);
					//}
					//printf("%d, %d\n", i, j);
					//}
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>

using namespace std;
typedef long long ll;

int gcd ( int a , int b )
{
    return (b==0) ? a : gcd ( b , a%b );
}

int floyd[107][107];
int fr[105];
int n,m,f;

void flloyd (  )
{

    for ( int mid=1 ; mid<=n ; mid++ )
    {
        for ( int i=1 ; i<=n ; i++ )
        {
            for ( int j=1 ; j<=n ; j++ )
            {
                floyd[i][j] = min ( floyd[i][j] , floyd[i][mid] + floyd[mid][j] );
            }
        }
    }

}

vector < int > v,w;
int const c = 10000000;

ll conv ( int x )
{

    int rem,bit=0,base=1;
    while (x>0)
    {
        rem = x%7;
        bit+= rem*base;
        x/=7;
        base*=10;
    }

    return bit;

}
bool vis[8];

bool dis ( int i )
{

    int x = i;
    if ( i==0 ) { if ( vis[0]==true ) { return 0; }  }
    while ( x>0 )
    {
        int rem = x%10;
        if ( !vis[rem] ) { vis[rem]=1; }
        else { return 0; }
        x /= 10;
    }

    return 1;

}

int a[10];

int main()
{
    ll n,m,lim=0,st=1,limm=0,stt=0,ans=0;
    cin>>n>>m;

    if ( n*m>=c ) { cout<<0; return 0; }

    int nn = conv(n);
    int mm = conv(m);
    a[1]=1;
    for ( int i=2 ; i<10 ; i++ ) { a[i]=a[i-1]*10; }

    while ( nn>0 ) { lim++; nn /= 10; }
    if ( lim!=1 )
    for ( int i=1 ; i<lim-1 ; i++ ) { st *= 10; }
    else { st=0; }
   //cout<<st<<endl<<lim<<endl;

       while ( mm>0 ) { limm++; mm /= 10; }
       if ( limm!=1 )
    for ( int i=1 ; i<limm-1 ; i++ ) { stt *= 10; }
    else { stt=0; }

    for ( int i=st ; i<n ; i++ )
    {
        memset ( vis , 0 , sizeof(vis) );
        ll x = conv(i);

        if ( x<a[lim] && lim>1 ) { vis[0]=1; }
        if ( dis(x) ) { v.push_back( x ); }
    }

    for ( int i=stt ; i<m ; i++ )
    {
        memset ( vis , 0 , sizeof(vis) );
        ll x = conv(i);
        if ( x<a[limm] && limm>1 ) { vis[0]=1; }
        if ( dis(x) ) { w.push_back( x ); }
    }

    /*for ( int i=0 ; i<v.size() ; i++ )
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
    for ( int j=0 ; j<w.size() ; j++ )
    {
        cout<<w[j]<<" ";
    }
    cout<<endl;*/

    for ( int i=0 ; i<v.size() ; i++ )
    {
        for ( int j=0 ; j<w.size() ; j++ )
        {
            memset ( vis , 0 , sizeof(vis) );
            ll y = v[i];
            ll z = w[j];
            if ( z<a[limm] && limm>1 ) { vis[0]=1; }
            if ( y<a[lim] && lim>1 ) { if ( vis[0] ) { continue; } vis[0]=1; }
            bool ok1=false,ok2=false;
            ok1 = dis(y);
            ok2 = dis(z);
            if ( ok1 && ok2 && ( y!=0 || z!=0 ) ) { ans++; }

        }

    }

    cout<<ans;

    return 0;
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
using namespace std;

const int mod=1000000007;
//const int mod=998244353;

int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long int t,n,m,k,q,x,a,b,c,d,w;
    cin>>n>>m;
    c=n;d=m;
    string s,s_;
    while (c>0) {
        s+=c%7+'0';
        c/=7;
    }
    while (d>0) {
        s_+=d%7+'0';
        d/=7;
    }
    if (s.length()+s_.length()>7) {
        cout<<0<<"\n";
    }
    else{
        long long int ans=0;
        vector<int> vec(7);
        a=s.length();
        b=s_.length();
        for(int i=0;i<n;i++){
            c=i;
            t=0;
            while (t<a) {
                vec[c%7]++;
                t++;
                c/=7;
            }
            for (int j=0; j<m; j++) {
                c=j;
                k=0;
                while (k<b) {
                    vec[c%7]++;
                    k++;
                    c/=7;
                }
                bool cond=true;
                for (int p=0; p<7; p++) {
                    if (vec[p]>1) {
                        cond=false;
                        break;
                    }
                }
                ans+=cond?1:0;
                c=j;
                k=0;
                while (k<b) {
                    vec[c%7]--;
                    k++;
                    c/=7;
                }
            }
            c=i;
            t=0;
            while (t<a) {
                vec[c%7]--;
                t++;
                c/=7;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;

}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <iomanip>

const long double PI(acosl(-1.0));
long double eps = 1e-10;

#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define sqr(x) ((x)*(x))
#define F first
#define S second
#define inf (int)(1e9+7)
#define infll (ll)(1e18+3)
#define sz(x) ((int)x.size())
#define bits(x) __builtin_popcount(x)
#define bitsl(x) __builtin_popcountll(x)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector < ll > vll;
typedef vector<int> vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector<vi> vii;
typedef int huint;

ll n, m, N, M;

ll cn(ll n) {
	int k = 0;
	while(n != 0) {k++; n/=7;}
	return k;
}

ll g(string& s) {
	ll k = 0;
	for (int i = 0; i < s.size(); i++)
		k=k*7+s[i]-'0';
	return k;
}
set<pair<string, string > > ss;

ll f(string& s) {
	ll k = 0;
	for (int i = 0; i < s.size(); i++)
		for (int j = i+1; j < s.size(); j++) {
			string a = s.substr(i, j-i), b = s.substr(j, 8);
			if (a == "") continue;
			if (b == "") continue;
			if (a.size() > N || b.size() > M) continue;
			// if (a[0] == '0' && a.size() > 1) a = a.substr(1);
			if (a.find("0") != string::npos && a.size() < N) continue;
			if (b.find("0") != string::npos && b.size() < M) continue;
			while (a.size() < N)
				a.insert(0, "0");
			while (b.size() < M)
				b.insert(0, "0");
			// if (b[0] == '0' && b.size() > 1) b = b.substr(1);
			if (ss.find(mp(a, b)) != ss.end()) continue;
			ss.insert(mp(a, b));

			ll A = g(a), B = g(b);
			if (A < n && B < m) {
				//cout << N << " " << M << " " << j-i+1 << " " << s.size()-j << " " << a << " " << b << endl;

				if (a.find("0") != string::npos && b.find("0") != string::npos)
					continue;
				k++;
				//cout << N << " " << M << " " << a.size() << " " << b.size() << " " << a << " " << b << endl;
				//cout << "+";
			}
		}
	return k;
}

int main() {

	freopen("input.txt", "r", stdin);

	cin >> n >> m;
	N = cn(n);
	M = cn(m);
	string s = "0123456";
	ll k = f(s);
	while(next_permutation(all(s)))
		k += f(s);

	cout << k;

	return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <iomanip>

const long double PI(acosl(-1.0));
long double eps = 1e-10;

#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define sqr(x) ((x)*(x))
#define F first
#define S second
#define inf (int)(1e9+7)
#define infll (ll)(1e18+3)
#define sz(x) ((int)x.size())
#define bits(x) __builtin_popcount(x)
#define bitsl(x) __builtin_popcountll(x)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector < ll > vll;
typedef vector<int> vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector<vi> vii;
typedef int huint;

ll n, m, N, M;

ll cn(ll n) {
	int k = 0;
	while(n != 0) {k++; n/=7;}
	return k;
}

ll g(string& s) {
	ll k = 0;
	for (int i = 0; i < s.size(); i++)
		k=k*7+s[i]-'0';
	return k;
}
set<pair<string, string > > ss;

ll f(string& s) {
	ll k = 0;
	for (int i = 0; i < s.size(); i++)
		for (int j = i+1; j < s.size(); j++) {
			string a = s.substr(i, j-i), b = s.substr(j, 8);
			if (a == "") continue;
			if (b == "") continue;
			if (a.size() > N || b.size() > M) continue;
			// if (a[0] == '0' && a.size() > 1) a = a.substr(1);
			if (a.find("0") != string::npos && a.size() < N) continue;
			if (b.find("0") != string::npos && b.size() < M) continue;
			while (a.size() < N)
				a.insert(0, "0");
			while (b.size() < M)
				b.insert(0, "0");
			// if (b[0] == '0' && b.size() > 1) b = b.substr(1);
			if (ss.find(mp(a, b)) != ss.end()) continue;
			ss.insert(mp(a, b));

			ll A = g(a), B = g(b);
			if (A < n && B < m) {
				//cout << N << " " << M << " " << j-i+1 << " " << s.size()-j << " " << a << " " << b << endl;

				if (a.find("0") != string::npos && b.find("0") != string::npos)
					continue;
				k++;
				//cout << N << " " << M << " " << a.size() << " " << b.size() << " " << a << " " << b << endl;
				//cout << "+";
			}
		}
	return k;
}

int main() {

	//freopen("input.txt", "r", stdin);

	cin >> n >> m;
	N = cn(n);
	M = cn(m);
	string s = "0123456";
	ll k = f(s);
	while(next_permutation(all(s)))
		k += f(s);

	cout << k;

	return 0;
}

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;

typedef vector<vector<int> > Graph;

ll fn2(int *V, int n, int m)
{
	//printf("2 %d %d\n", n,m);
	if (n == 0) {
		return 1;
	}
	ll ret = 0;
	int d = n/7 >= 1 ? 7 : n%7;
	for (int i=0; i<d; i++) {
		if (V[i] == 0) {
			V[i] = 1;
			ret += fn2(V, n/7, m);
			V[i] = 0;
		}
	}
	return ret;
}

ll fn(int *V, int n, int m)
{
	//printf("1 %d %d\n", n,m);
	if (m == 0) {
		return fn2(V,n,m);
	}
	ll ret = 0;
	int d = m/7 > 7 ? 7 : m%7;
	for (int i=0; i<d; i++) {
		if (V[i] == 0) {
			V[i] = 1;
			ret += fn(V, n, m/7);
			V[i] = 0;
		}
	}
	return ret;
}

int main()
{
	int n,m;
	scanf("%d%d", &n, &m);

	int d1 = (int)ceil(log((double)n)/log(7.0));
	int d2 = (int)ceil(log((double)m)/log(7.0));
	if (d1 + d2 > 7) {
		printf("0\n");
		return 0;
	}

	int V[7] = {0};
	printf("%I64d\n", fn(V,n,m));
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair <int,int> pii;

#define trace(x) cout << #x << "  " << x << endl
#define fors(i, a, b) for (int i = (a); i < int(b); i++)
#define rep(i, n) fors(i, 0, n)
int rjes;
ll n,m,br1,br2,pot[110],cd,bio[200];

ll cnt(ll x){
	ll y = 0;
	while(x != 0){
		x /= 10;
		y++;
	}

	return y;
}

ll pret(ll x){
	ll z = 0;
	int flag = 0;
	for(int y = 8;y >= 0;y--){
		if(x / pot[y] != 0){
			flag = 1;

			z += x /pot[y];

			x = x % pot[y];

		}
		if(flag&&y != 0){
			z *= 10;
		}
	}

	return z;
}

int main(){

	scanf("%lld %lld",&n,&m);
	pot[0] = 1;
	fors(i,1,23){
		pot[i] = pot[i - 1] * 7;
	}
	//printf("bio %lld\n",pret(n));
	br1 = cnt(pret(n - 1));
	br2 = cnt(pret(m - 1));
	//printf("bio %lld %lld %lld %lld\n",br1,br2,pot[br1],pot[br2]);
	if(br1 + br2 > 7){
		printf("0");

	}
	else{

		rep(i,pot[br1]){
			rep(j,pot[br2]){
				rep(k,11){
					bio[k] = 0;
				}
				cd = 0;
				//printf("bio1 %d %d\n",i,j);
				if(i < n&&j < m){

					if((br1 + br2)- (cnt(pret(i)) + cnt(pret(j))) > 1){

						continue;
					}
					else if((br1 + br2)- (cnt(pret(i)) + cnt(pret(j))) == 1){
						bio[0]++;

					}
					ll di = pret(i);
					ll dj = pret(j);
					//printf("bio2 %d %d\n",i,j);
					while(di != 0){
						bio[di % 10]++;
						if(bio[di % 10] > 1){
							cd = 1;
						}

						di /= 10;
					}

					while(dj != 0){
						bio[dj % 10]++;
						if(bio[dj % 10] > 1){
							cd = 1;
						}

						dj /= 10;
					}

					if(!cd&&(i != 0||j != 0)){

						rjes++;
						//printf("%d\n",rjes);
					}
				}
			}
		}
		printf("%d\n",rjes);
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double
#define db double
#define str string
#define int long long

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>

#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18;
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

int32_t main()
{
    int n,m;
    cin>>n>>m;
    int len1=1,len2=1;
    int a=7;
    while((a*7)<n)
    {
        len1++;
        a*=7;
    }
    a=7;
    while((a*7)<m)
    {
        len2++;
        a*=7;
    }
    if((len1+len2>7))
    {
        cout<<0<<"\n";
        return 0;
    }
    int res=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            map< int,int > mp;
            int c1=i,c2=j;
            int l1=0,l2=0;
            while(c1)
            {
            //cout<<(c1%7)<<"\n";
                mp[c1%7]++;
                c1/=7;
                l1++;
            }
            while(c2)
            {
                //cout<<(c2%7)<<"\n";
                mp[c2%7]++;
                c2/=7;
                l2++;
            }
            if(l1<len1)
             mp[0]++;
            if(l2<len2)
             mp[0]++;
            int f=1;
            for(int k=0;k<7;k++)
            {
                if(mp[k]>1)
                {
                    f=0;
                    break;
                }
            }
            if(f)
             res++;
        }
    }
    cout<<res<<"\n";
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
ll x , y , n , ans , m,nb,mb;
ll noOfBits(long long x , long long y)
{
	ll ans = 0;
	if(x == 0)
		return 1;
	while(x > 0)
	{
		x = x/y;
		ans++;
	}
	return ans;
}

bool allDifferent(ll x , ll y)
{
	ll xx , yy;
	bool b[7] = {0};
	xx = nb , yy = mb;
	while(xx > 0)
	{
		if(b[x%7] == 0)
			b[x%7] = 1;
		else
			return false;
		x /= 7;
		xx--;
	}

	while(yy > 0)
	{
		if(b[y%7] == 0)
			b[y%7] = 1;
		else
			return false;
		y = y/7;
		yy--;
	}
	return true;
}
set < pair < ll , ll >  > set1;
int	 main()
{
	string s ;
	cin >> n >> m;
	ans = 0;
		nb = noOfBits(n,7);
		mb = noOfBits(m,7);
		if(nb + mb > 8)
		{
			cout << "0\n" ; exit(0);
		}

		for(ll i = 0 ; i < n ; i++)
		{
			for(ll j = 0 ; j < m ; j++)
			{
				if(allDifferent(i,j)){
					set1.insert({i,j});
				}
			}
		}
		cout << set1.size() << endl;
	return 0;
}

#include <bits/stdc++.h>

#ifdef LOCAL_COMP
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL(0,__VA_ARGS__, 5,4,3,2,1)
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N

#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro ## nargs

#define debug(...) macro_dispatcher(debug, __VA_ARGS__)(__VA_ARGS__)

#define debug1(a)       cout<< #a << " = " << (a) << endl
#define debug2(a,b)     cout<< #a << " = " << (a) << "  " << #b << " = " << (b) << endl
#define debug3(a,b,c)   cout<< #a << " = " << (a) << "  " << #b << " = " << (b) << "  " \
  << #c << " = " << (c) << endl
#define debug4(a,b,c,d) cout<< #a << " = " << (a) << "  " << #b << " = " << (b) << "  " \
  << #c << " = " << (c) << "  " << #d << " = " << (d) << endl
#else
#define debug(...)
#endif

using namespace std;

typedef long long T;

T pow2[20];

int convert(T x, T size) {
  int mask = 0;

  while (x > 0) {
    int mod = x % 7;
    if (mask & pow2[mod]) {
      return -1;
    }
    mask |= pow2[mod];
    x /= 7;
    --size;
  }

  if (size >= 2) {
    return -1;
  }

  if (size == 1) {
    if (mask & pow2[0]) {
      return -1;
    } else {
      mask |= pow2[0];
    }
  }

  return mask;
}

int get_size(int x) {
  int size = 0;

  while (x > 0) {
    ++size;
    x /= 7;
  }

  if (size == 0) {
    size = 1;
  }

  return size;
}

T stupid_check(T a_mask, T b_mask) {
  if (a_mask & b_mask) {

  } else {
    if (a_mask >= 0 && b_mask >= 0) {
      return true;
    }
  }
  return false;
}

T stupid_solve(T n, T m) {
  int n_size = get_size(n), m_size = get_size(m);

  T ret = 0;
  for (int a = 0; a < n; ++a) {
    for (int b = 0; b < m; ++b) {
      int a_mask = convert(a, n_size), b_mask = convert(b, m_size);
      if (stupid_check(a_mask, b_mask)) {
        ++ret;
      }
    }
  }
  return ret;
}

T calc(T hours, T minutes, T n, T m) {

}

T solve(T n, T m = -1) {
  if (m < 0) {
    cin >> m;
  }

  int base_n_size = get_size(n), base_m_size = get_size(m);

  if (base_n_size + base_m_size > 8) {
    return 0;
  }

  int n_size = base_n_size, m_size = base_m_size;

  T ret = 0;
  for (T a = 0; get_size(a) <= n_size && a < n; ++a) {
    for (T b = 0; get_size(b) <= m_size && b < m; ++b) {
      int a_mask = convert(a, n_size), b_mask = convert(b, m_size);
      if (stupid_check(a_mask, b_mask)) {
        ++ret;
      }
    }
  }

  return ret;

  int total_size = n_size + m_size;

  for (T a = 0; ; ++a) {
    if (get_size(a) > total_size) {
      break;
    }

    int mask = convert(a, total_size);
    if (mask < 0) {
      continue;
    }

    vector<int> digs;
    T cur = a;
    for (int i = 0; i < total_size; ++i) {
      digs.push_back(cur % 7);
      cur /= 7;
    }
    reverse(digs.begin(), digs.end());

    vector<int> lefts(total_size, 0);
    lefts[0] = digs[0];
    for (int i = 1; i < total_size; ++i) {
      lefts[i] = lefts[i - 1] * 7 + digs[i];
    }

    vector<int> rights(total_size, 0);
    rights[total_size - 1] = digs[total_size - 1];
    T seven = 7;
    for (int i = total_size - 2; i >= 0; --i) {
      rights[i] = digs[i] * seven + rights[i + 1];
      seven *= 7;
    }
//    reverse(rights.begin(), rights.end());

    for (int i = 0; i < n_size; ++i) {
//      T left_mask = convert(lefts[i], n_size), right_mask = convert(rights[i], m_size);
      if (lefts[i] < n && rights[i + 1] < m) {
        ++ret;
      }
    }
  }

//  cout << ret << endl;
  return ret;
}

int main() {
#ifdef LOCAL_COMP
  freopen("a.txt", "r", stdin);
#endif

  pow2[0] = 1;
  for (int i = 1; i < 20; ++i) {
    pow2[i] = pow2[i - 1] * 2;
  }

//  for (int iter = 0; iter < 1000; ++iter) {
//    T n = rand() % 10000 + 1;
//    T m = rand() % 10000 + 1;
////  for (int n = 1; n < 100; ++n) {
////    for (int m = 1; m < 100; ++m) {
//      T stupid = stupid_solve(n, m);
//      T smart = solve(n, m);

//      debug(n, m, stupid, smart);
//      assert(stupid == smart);
////    }
//  }

#if 1
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  for (int n; cin >> n; ) {
    cout << solve(n) << endl;
//    while(n--) {
//      solve(n);
//    }
//    if (solve(n)) {
//      cout << "YES" << endl;
//    } else {
//      cout << "NO" << endl;
//    }
  }
  cout.flush();
#else
  int n;
  while (scanf("%d", &n) == 1) {
    solve(n);
  }
#endif

  return 0;
}

#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

vector<ll> GetDigits(ll k)
{
	vector<ll> maxDigits;
	while (k)
	{
		maxDigits.push_back(k % 7);
		k /= 7;
	}

	if (maxDigits.size() == 0)
		maxDigits.push_back(0);

	return maxDigits;
}

ll GetMinNumber(vector<ll>& v)
{
	if (v.size() <= 2) return 0;

	ll minNumber = 1;
	for (int i = 1; i < v.size() - 1; i++)
		minNumber *= 7;

	return minNumber;
}

bool AllNumbersDifferent(vector<ll>& v)
{
	int digits[7] = {};
	for (auto num : v)
		digits[num]++;

	for (int i = 0; i < 6; i++)
		if (digits[i] > 1)
			return false;

	return true;
}

bool BothNumbersAreDifferent(vector<ll>& digitsN, vector<ll>& digitsM)
{
	int digits[7] = {};
	for (auto num : digitsN)
		digits[num]++;
	for (auto num : digitsM)
		digits[num]++;

	for (int i = 0; i < 6; i++)
		if (digits[i] > 1)
			return false;

	return true;
}

vector< vector<ll> > GetNumbersWithDifferentDigits(vector<ll> maxDigits, ll n)
{
	vector< vector<ll> > numbersWithDifferentDigits;
	for (int i = GetMinNumber(maxDigits); i < n; i++)
	{
		auto digits = GetDigits(i);
		while (digits.size() < maxDigits.size())
			digits.push_back(0);
		if (AllNumbersDifferent(digits))
			numbersWithDifferentDigits.push_back(digits);
	}

	return numbersWithDifferentDigits;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
#endif

	ll n, m;
	cin >> n >> m;

	auto maxNDigits = GetDigits(n - 1);
	auto maxMDigits = GetDigits(m - 1);

	if (maxNDigits.size() > 7 || maxMDigits.size() > 7)
	{
		cout << 0;
		return 0;
	}

	auto differentN = GetNumbersWithDifferentDigits(maxNDigits, n);
	auto differentM = GetNumbersWithDifferentDigits(maxMDigits, m);

	ll total = 0;
	for (auto i : differentN)
		for (auto j : differentM)
			if (BothNumbersAreDifferent(i, j))
				total++;

	cout << total;
}

//hi
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define LL long long int
set< pair<int,int> > a;
int main(void){
    int n,m;
    scanf("%d%d",&n,&m);
    int i,j,i2;
    int s[7]={0,1,2,3,4,5,6};
    int n2=n,cntn=0;
    while(n2){
		cntn++;
		n2=n2/7;
	}
	int m2=m, cntm=0;
	while(m2){
		cntm++;
		m2=m2/7;
	}
	if(cntm+cntn>7){
		printf("0\n");
		return 0;
	}
    do{
		for(i=0;i<6;i++)
			for(j=i+1;j<7;j++){
				int nn=0,mm=0;
				string aa="", bb="";
				for(i2=0;i2<=i;i2++) nn=nn*7+s[i2], aa+=to_string(s[i2]);
				for(i2=i+1;i2<=j;i2++) mm=mm*7+s[i2], bb+=to_string(s[i2]);
				if(nn<n&&mm<m){
					for(i2=i+1;i2<cntn;i2++) aa="0"+aa;
					for(i2=j-i;i2<cntm;i2++) bb="0"+bb;
					int zr=0;
					for(i2=0;i2<aa.length();i2++) if(aa[i2]=='0') zr++;
					for(i2=0;i2<bb.length();i2++) if(bb[i2]=='0') zr++;
					if(zr<=1){
						a.insert(MP(nn,mm));
					}
				}
			}
	}while(next_permutation(s,s+7));
	printf("%d\n",a.size());
	/*for(auto it=a.begin();it!=a.end();it++){
		printf("%d %d\n",it->F,it->S);
	}*/
    return 0;
}

/*input
1 2
*/
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pii pair<long long,long long>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
vector <string> v1,v2;
string findbin(ll num,ll digits)
{
	string s="";
	while(num>0)
	{
		s = s + (char)(num%7 + 48);
		num = num/7;
	}
	reverse(s.begin(),s.end());
	while(s.length() < digits)
		s = "0"+s;
	return s;
}
int main()
{
	std::ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	ll d1=0;
	ll num=n-1;
	while(num>0)
	{
		d1++;
		num = num/7;
	}
	ll d2=0;
	num=m-1;
	while(num>0)
	{
		d2++;
		num = num/7;
	}
	if(d1+d2>7)
	{
		cout<<"0"<<endl;
		return 0;
	}
	//debug(d1);
	//debug(d2);
	/*if(d1-1>0)
	{
		ll dig = d1-1;
		ll st = ceil(pow(7,dig-1));
		ll en = ceil(pow(7,dig));
		F(i,st,min(n-1,en-1))
		{
			string s = findbin(i,d1);
			ll l = s.length();
			bool f=0;
			F(i,0,l-1)
			{
				F(j,0,l-1)
				{
					if(i==j)
						continue;
					if(s[i] == s[j])
						f=1;
				}
			}
			if(!f)
				v1.push_back(s);
		}
	}*/
	if(d1>0)
	{
		ll dig = 0;
		ll st = ceil(pow(7,dig));
		ll en = ceil(pow(7,d1+1));
		F(i,st,min(n-1,en-1))
		{
			string s = findbin(i,d1);
			ll l = s.length();
			bool f=0;
			F(i,0,l-1)
			{
				F(j,0,l-1)
				{
					if(i==j)
						continue;
					if(s[i] == s[j])
						f=1;
				}
			}
			if(!f)
				v1.push_back(s);
		}
	}
	if(d1<=1)
		v1.pb("0");
	/*if(d2-1>0)
	{
		ll dig = d2-1;
		ll st = ceil(pow(7,dig-1));
		ll en = ceil(pow(7,dig));
		F(i,st,min(m-1,en-1))
		{
			string s = findbin(i,d2);
			ll l = s.length();
			bool f=0;
			F(i,0,l-1)
			{
				F(j,0,l-1)
				{
					if(i==j)
						continue;
					if(s[i] == s[j])
						f=1;
				}
			}
			if(!f)
				v2.push_back(s);
		}
	}*/
	if(d2>0)
	{
		ll dig = 0;
		ll st = ceil(pow(7,dig));
		ll en = ceil(pow(7,d2+1));
		F(i,st,min(m-1,en-1))
		{
			string s = findbin(i,d2);
			ll l = s.length();
			bool f=0;
			F(i,0,l-1)
			{
				F(j,0,l-1)
				{
					if(i==j)
						continue;
					if(s[i] == s[j])
						f=1;
				}
			}
			if(!f)
				v2.push_back(s);
		}
	}
	if(d2==1)
		v2.pb("0");
	ll sz1 = v1.size();
	ll sz2 = v2.size();
	ll ans=0;
	F(i,0,sz1-1)
	{
		string s1 = v1[i];
		ll l1 = s1.length();
		//cout<<s1<<endl;
		F(j,0,sz2-1)
		{
			string s2 = v2[j];
			//cout<<s2<<" ";
			ll l2 = s2.length();
			bool f=0;
			F(i,0,l1-1)
			{
				F(j,0,l2-1)
				{
					if(s1[i] == s2[j])
					{
						f=1;
						break;
					}
				}
				if(f)
					break;
			}
			if(!f)
			{
				ans++;
				//cout<<s1<<" "<<s2<<endl;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
using namespace std;
int a[10];
map <pair<int, int>, bool> mp;
int main()
{
	int n, m, x = 0, y = 0, i, j, k, p, ans = 0;
	scanf("%d%d", &n, &m);
	int n0 = n, m0 = m;
	while (n0 != 0)
	{
		n0 /= 7;
		x++;
	}
	while (m0 != 0)
	{
		m0 /= 7;
		y++;
	}
	if (x + y > 7)
	{
		printf("0\n");
		return 0;
	}
	for (i = 0; i < 7; i++) a[i] = i;
	do
	{
		k = 0;
		p = 0;
		for (i = 0; i < x; i++) k = k * 7 + a[i];
		if (k>=n) continue;
		for (i = x; i < x + y; i++) p = p * 7 + a[i];
		if (p>=m) continue;
		if (!mp[{k, p}])
		{
			mp[{k, p}] = 1;
			ans++;
		}
	} while (next_permutation(a, a + 7));
	printf("%d\n", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#ifndef DEBUG
#define endl '\n'
#define debugf(...)
#define debug(...)
#else
#define debugf(...) printf(__VA_ARGS__)
#define debug(...) __VA_ARGS__
#endif

using ll = long long;
#define int ll
const int N = 1e5 + 5;

int positions(int x) {
	int ans = 0;
	while (x > 0) {
		ans++;
		x /= 7;
	}
	return ans;
}

bool valid(int x, int y, int px, int py) {
	static bitset<7> seen;
	seen.reset();

	while (px > 0) {
		int d = x % 7;
		x /= 7;
		px--;

		if (seen[d]) return false;
		seen.set(d);
	}

	while (py > 0) {
		int d = y % 7;
		y /= 7;
		py--;

		if (seen[d]) return false;
		seen.set(d);
	}

	return true;
}

int32_t (((((main)))))() <%
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int n, m;
	cin >> n >> m;

	int pos_n = positions(n);
	int pos_m = positions(m);

	debugf("%d %d...\n", pos_n, pos_m);

	if (pos_n + pos_m > 7) {
		cout << "0\n";
		return 0;
	}

	// Should be fine, I think
	int ans = 0;
	for (int i = 0; i < n; i++) { // same as `for i in 0..n*m`
		for (int j = 0; j < m; j++) {
			if (valid(i, j, pos_n, pos_m)) {
				ans++;
				debugf("%d:%d\n", i, j);
			}
		}
	}

	cout << ans << endl;

	return 0;
%>

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
const int MAX_N=15;
vector <int> num;
vector <int> mum;
int x[MAX_N];
int y[MAX_N];
int dec(long long n,int a[])
{
	int i=0;
	for (i=0;n>0;i++)
	{
		a[i]=n%7;
		n/=7;
	}
	int b;
	for (int j=0;j<i/2;j++)
	{
		b=a[j];
		a[j]=a[i-j-1];
		a[i-j-1]=b;
	}
	return i;
}
bool raz(long long a,int b)
{
	int q[10];
	for (int i=0;i<10;i++)
		q[i]=0;
	int j=0;
	for (j=0;j<b;j++)
	{
		q[a%10]++;
		a/=10;
	}

	for (int i=0;i<10;i++)
		if (q[i]>1)
			return 1;
	return 0;
}
bool raz2(long long a,int ab,long long b,int bb)
{
	int q[10];
	for (int i=0;i<10;i++)
		q[i]=0;
	int j=0;
	for (j=0;j<ab;j++)
	{
		q[a%10]++;
		a/=10;
	}
	for (j=0;j<bb;j++)
	{
		q[b%10]++;
		b/=10;
	}
	for (int i=0;i<10;i++)
		if (q[i]>1)
			return 1;
	return 0;
}
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt", "w", stdout);
	long long n,m;
	cin>>n>>m;
	int a=dec(n,x),b=dec(m,y);
	long long p=0,l=0;
	for (int i=0;i<a;i++)
		p=p*10+x[i];
	for (int i=0;i<b;i++)
		l=l*10+y[i];
	if (a+b>7)
	{
		cout<<"0";
		return 0;
	}
	for (int i1=0;i1<7;i1++)
	{
		for (int i2=0;i2<7;i2++)
		{
			for (int i3=0;i3<7;i3++)
			{
				for (int i4=0;i4<7;i4++)
				{
					for (int i5=0;i5<7;i5++)
					{
						for (int i6=0;i6<7;i6++)
						{
							for (int i7=0;i7<7;i7++)
							{
								for (int i8=0;i8<7;i8++)
								{
									long long g=i8+10*(i7+i6*10+i5*100+i4*1000+i3*10000+i2*100000+i1*1000000);
									if (g<p&&raz(g,a)==0)
										num.push_back(g);
									if (g<l&&raz(g,b)==0)
										mum.push_back(g);
								}
							}
						}
					}
				}
			}
		}
	}
	long long ans=0;
	for (int i=0;i<num.size();i++)
	{
		for (int j=0;j<mum.size();j++)
		{
			if (raz2(num[i],a,mum[j],b)==0)
				ans++;
		}
	}
	cout<<ans;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define LL long long
#define pb push_back
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))

const int N = 3e5 + 5;
vector<int>g[N];
int ans[N], tot[N];
pii dfs(int u) {
	pii mx = mp(tot[u] - 1,u);
	for (int i = 0; i < g[u].size(); i++) {
		pii tmp = dfs(g[u][i]);
		mx = max(mx, tmp);
	}
	if(mx.fi <= tot[u] / 2) {
		ans[u] = mx.se;
		return mx;
	}
	else {
		ans[u] = u;
		return mp(tot[u] - 1, u);
	}
}
int Dfs(int u) {
	tot[u] = 0;
	for (int i = 0; i < g[u].size(); i ++) {
		tot[u] += Dfs(g[u][i]);
	}
	return tot[u] + 1;
}
int main() {
	int n, p, u, q;
	scanf("%d%d", &n, &q);
	for (int i = 2; i <= n; i++) {
		scanf("%d", &p);
		g[p].pb(i);
	}
	Dfs(1);
	dfs(1);
	while (q--) {
		scanf("%d", &u);
		printf("%d\n",ans[u]);
	}
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <fstream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>

typedef long long ll;
using namespace std;

void solveC();
pair<ll,ll> solveA();
pair<int,int> solveAA();
int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0);
	int test = 1;
	while (test--)
	{
		//pair<ll,ll> f = solveA();
		//pair<ll, ll> s = solveAA();
		//cout << f.first << " " << f.second << endl << s.first<< " " << s.second << endl;
		solveC();
	}
	return 0;
}

int convert(string s)
{
	int ans = 0;
	int deg = 1;
	for (int i = s.size() - 1; i >= 0; deg*=7,i--)
		ans += (s[i] - '0')*deg;
	return ans;
}
string count(int n)
{
	int ans = 0;
	string s = "";
	while (n)
	{
		s += ((n % 7) + '0');
		n /= 7;
	}
	return s;
}

pair<int, int> solveAA()
{

	int n, i, d, c = 0;
	long long x;
	char s;
	cin >> n >> x;
	for (i = 0; i < n; i++)
	{
		cin >> s >> d;
		if (s == '+')
			x = d + x;
		else
			if (s == '-')
			{
				if (x >= d)
					x = x - d;
				else
					c++;
			}
	}
	return make_pair(x, c);
}
#define int long long

pair<int,int> solveA()
{
	int n, x;
	int sad = 0;
	cin >> n >> x;
	for (int i = 0; i < n; i++)
	{
		char sign;
		int d;
		cin >> sign >> d;
		if (sign == '+')
			x += d;
		else
		{
			if (d > x)
				sad++;
			else
				x -= d;
		}
	}

	return make_pair(x, sad);
}

int ans = 0;
string s = "0123456";
int ns, ms;
int n, m;
set<pair<int,int> > ss;
void gen(int k)
{
	if (k == 6)
	{
		int nn = convert(s.substr(0, ns));
		int mm = convert(s.substr(ns, ms));
		if (nn < n && mm < m)
		{
			ss.insert(make_pair(nn, mm));
		}
		return;
	}
	for (int i = k; i < 7; i++)
	{
		swap(s[i], s[k]);
		gen(k + 1);
		swap(s[i], s[k]);
	}
}

void solveC()
{
	int MAX = 114382;

	cin >> n >> m;
	if (n > MAX || m > MAX)
	{
		cout << 0 << endl;
		return;
	}

	ns = count(n).size();
	ms = count(m).size();

	if (ns+ ms> 7)
	{
		cout << 0 << endl;
		return;
	}
	gen(0);
	cout << ss.size();
}

#include<bits/stdc++.h>
using namespace std;
map<int,int> b;
long long convert(int n)
{
    long long c=0,ans=0;
    while(n>0)
    {
        ans=(pow(10,c)*(n%7))+ans;
        n/=7;
        c++;
    }
        return ans;
}
int log7(int n)
{
int c=1;
while(n>=7)
{
    n/=7;
    c++;
}
return c;
}
int main()
{
    int c=0,n,m;
    cin>>n>>m;
    if(log7(n-1)+log7(m-1)<=7)
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
              {
            b.clear();
            b[0]+=log7(n-1)-log7(i);
            long long n1=convert(i);
            while(n1>0)
                {
                    b[n1%10]++;
                    n1/=10;
                }
                if(i==0)
                    b[0]++;
                    bool flag=false;
                    b[0]+=log7(m-1)-log7(j);
                    long long m1=convert(j);
                    while(m1>0)
                    {
                        b[m1%10]++;
                        m1/=10;
                    }
                if(j==0)
                    b[0]++;
                    cout<<convert(i)<<" "<<convert(j)<<endl;
                    for(auto it=b.begin();it!=b.end();it++)
                    {
                        cout<<it->first<<" "<<it->second<<endl;
                        if(it->second>1)
                         flag=true;
                    }
                    cout<<endl;
                    if(flag==false)
                        c++;
                }
        }
    }
cout<<c<<endl;
return 0;
}

#include <bits/stdc++.h>

using namespace std;

#ifdef WIN32
	#define I64 "%I64d"
#else
	#define I64 "%lld"
#endif

typedef long long ll;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
#define sz(s) (int(s.size()))
#define fname "a"

int n, m;
vector <int> a, b;
int p[11];
int p2[11];

inline int check(int l, int r, const vector<int>& a) {
    for (int i = l, j = 0; i <= r; ++i, ++j)
        if (a[j] != p[i]) return a[j] > p[i] ? 1 : 0;
    return 0;
}

int main()
{
	#ifdef LOCAL
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif
    scanf("%d%d", &n, &m);
    for (int i = n; i; i /= 7)
        a.pb(i % 7);
    for (int i = m; i; i /= 7)
        b.pb(i % 7);
    if (sz(a) + sz(b) > 7) {
        puts("0");
        return 0;
    }
    for (int i = 0; i < 7; ++i)
        p[i] = i;
    p2[0] = -1;
    int ans = 0;
    do {
        int ok = 1;
        for (int i = 0; i < sz(a) + sz(b); ++i)
            if (p[i] != p2[i]) ok = 0;
        if (ok) continue;
        ans += check(0, sz(a) - 1, a) & check(sz(a), sz(a) + sz(b) - 1, b);
        memcpy(p2, p, sizeof(p2));
    } while(next_permutation(p, p + 7));
    printf("%d\n", ans);
    return 0;
}

#include<iostream>
#include<stdio.h>
#include<algorithm>

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
int ipow(int n, int k)
{
	int ans=1;
	rep(i,0,k) ans*=n;
	return ans;
}
int main()
{
    int n,m;
	scanf("%d %d\n",&n,&m);
	int kn=0,km=0;
	int nn=n-1,mm=m-1;
	while(nn>0)
	{
		kn++;
		nn/=7;
	}
	while(mm>0)
	{
		km++;
		mm/=7;
	}
	if(kn=0) kn=1;
	if(km=0) km=1;
	//printf("%d %d\n",kn,km);
	if(kn>6||km>6)
	{
		printf("0\n");
		return 0;
	}
	int ans=0;
	int a[7];
	int ii;
	if(kn+km<=7)
	{
		rep(i,0,ipow(7,kn+km))
		{
			rep(j,0,7) a[j]=0;
			nn = i/ipow(7,km);
			mm = i% (ipow(7,km));
			//printf(" %d %d;",nn,mm);
			ii=i;
			rep(j,0,kn+km)
			{
				if(a[ii%7]==0)
				{
					a[ii%7]++;
					ii/=7;
				}else
				{
					ii=-1;
					break;
				}
			}
			if(ii==(-1) ) continue;
			//printf("%d %d;",nn,mm);

			if(nn<n && mm<m)
			{
				ans++;
				//printf("%d %d;",nn,mm);
			}
		}
	}

	/*
	rep(i,0,ipow(7,kn))
	{
		rep(j,0,7) a[j]=0;
		a[0]=1;
		nn = i;

		//printf(" %d %d;",nn,mm);
		ii=i;
		rep(j,0,kn)
		{
			if(a[ii%7]==0)
			{
				a[ii%7]++;
				ii/=7;
			}else
			{
				ii=-1;
				break;
			}
		}
		if(ii==(-1) ) continue;
		//printf("%d %d;",nn,mm);

		if(nn<n && nn>0 )
		{
			ans++;
			printf("%d %d;",nn,0);
		}
	}

	rep(i,0,ipow(7,km))
	{
		rep(j,0,7) a[j]=0;
		a[0]=1;
		mm = i;
		//printf(" %d %d;",nn,mm);
		ii=i;
		rep(j,0,km)
		{
			if(a[ii%7]==0)
			{
				a[ii%7]++;
				ii/=7;
			}else
			{
				ii=-1;
				break;
			}
		}
		if(ii==(-1) ) continue;
		//printf("%d %d;",nn,mm);

		if( mm<m && mm>0)
		{
			ans++;
			printf("%d %d;",0,mm);
		}
	}
	*/

	//printf("\n");

	printf("%d\n",ans);

	return 0;
}

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <random>
#include <stdio.h>
#include <string>
#include <vector>

#define SZ(x) (int)(x.size())
#define F0(i,n) for(int i=0;i<n;i++)
#define F1(i,n) for(int i=1;i<=n;i++)
#define FI(i,n) for(int i=0;i<=n;i++)
#define TR(x) cout << #x << " = " << x << endl
#define FE(k) get<0>(k)
#define SE(k) get<1>(k)
#define TH(k) get<2>(k)
#define TRAV(a, x) for(auto &a: x)
#define _ << " " <<
#define INF 1E9
#define INF64 1E18

using namespace std;

template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
  pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
  pr("{",x.first,", ",x.second,"}");
}
template<class T> void prContain(const T& x) {
  pr("{");bool fst = 1; TRAV(a,x) pr(!fst?", ":"",a), fst = 0;pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

void ps() { pr("\n"); }
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
  pr(first," "); ps(rest...); // print w/ spaces
}

template<typename T> int remin(T& a,const T& b){if(b<a){a=b;return true;}return false;}
template<typename T> int remax(T& a,const T& b){if(b>a){a=b;return true;}return false;}

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

const int BASE = 7;
int N, M;
int dn, dm;
int has[10];
int ans;

int dec(int n) {
  int ret = 0;
  while (n >= BASE) {
    n = n / BASE;
    ++ret;
  }
  return ret+1;
}

void dfs(int ni, int nm, int n, int m) {
  // ps(ni, nm, n, m);
  if (ni < dn) {
    for (int i = 0; i < BASE; ++i) {
      if (!has[i]) {
        has[i] = true;
        dfs(ni+1, nm, n * BASE + i, m);
        has[i] = false;
      }
    }
    return;
  }

  if (nm < dm) {
    for (int i = 0; i < BASE; ++i) {
      if (!has[i]) {
        has[i] = true;
        dfs(ni, nm + 1, n, m * BASE + i);
        has[i] = false;
      }
    }
    return;
  }
  if (n < N && m < M) {
    // ps(n, m);
    ans++;
  }
}

int main(int argc, const char **argv) {
  scanf("%d%d", &N, &M);
  dn = dec(N);
  dm = dec(M);
  // ps(dn, dm);
  dfs(0, 0, 0, 0);
  ps(ans);
}

#include <iostream>
#include <vector>
#include <string.h>
#include <stdio.h>

using namespace std;

int len;
int len1,len2;
int n,m;
int res=0;
long long int pow7[10];

int check(string s){
	int i=0;
	long long int N=0;
	for(int k=len1-1;i<len1;i++,k--)
		N+=((long long int)(s[i]-'0')*pow7[k]);
	if(N>=n)
		return 0;
	N=0;
	for(int k=len2-1;i<len;i++,k--)
		N+=((long long int)(s[i]-'0')*pow7[k]);
	if(N>=m)
		return 0;
	//cout<<s<<"\n";
	return 1;
}

void reco(string s){
	if(s.size()==len){
		res+=check(s);
		return ;
	}
	int f;
	for(int i=0;i<7;i++){
		char ch='0'+i;
		f=0;
		for(int j=0;j<(int)s.size();j++)
			if(s[j]==ch){
				f=1;
				break;
			}
		if(!f)
			reco(s+ch);
	}
	return ;
}

int main(){
	pow7[0]=1;
	for(int i=1;i<10;i++)
		pow7[i]=pow7[i-1]*7;
	cin>>n>>m;
	int temp=n-1;
	while(temp){
		temp/=7;
		len1++;
	}
	temp=m-1;
	while(temp){
		temp/=7;
		len2++;
	}
	len=len1+len2;
	reco("");
	cout<<res<<"\n";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define sz(x) (int)(x).size()
#define F first
#define S second
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector< pii > vii;
typedef vector< vi > vvi;

int n, m;
int l, r;
int buff[7];
int ans;
set<int> st;

bool check() {
	int h = 0;
	int sev = 1;
	for (int i = l-1; ~i; i--) {
		h += buff[i] * sev;
		sev *= 7;
	}

	int mi = 0;
	sev = 1;
	for (int i = l + r - 1; i >= l; i--) {
		mi += buff[i] * sev;
		sev *= 7;
	}

	st.clear();
	for (int i = 0; i < l + r; i++) {
		if (st.count(buff[i])) return false;
		st.insert(buff[i]);
	}

	return mi < m && h < n;
}

void gen(int i) {
	if (i == l + r) {
		ans += check();
		return;
	}
	for (int j = 0; j < 7; j++) {
		buff[i] = j;
		gen(i+1);
	}
}

int find(int x) {
	int ret = 0;
	ll sev = 1;
	while (true) {
		if (x <= sev)
			return ret;
		sev *= 7;
		ret++;
	}
	return -1;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	l = find(n);
	r = find(m);
	if (l + r > 7) return 0*puts("0");
	gen(0);
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
#define sflld(n) scanf("%lld",&n)
#define sfulld(n) scanf("%llu",&n)
#define sfd(n) scanf("%d",&n)
#define sfld(n) scanf("%ld",&n)
#define sfs(n) scanf("%s",&n)
#define ll long long
#define s(t) int t; while(t--)
#define ull unsigned long long int
#define pflld(n) printf("%lld\n",n)
#define pfd(n) printf("%d\n",n)
#define pfld(n) printf("%ld\n",n)
#define lt 2*idx
#define rt 2*idx+1
#define f(i,k,n) for(i=k;i<n;i++)
#define MAXN 0
#define FD freopen("out.txt", "w", stdout);
#define FC fclose(stdout);

using namespace std;
long long C(int n, int r, int MOD)
{
    vector< vector<long long> > C(n+1,vector<long long> (r+1,0));

    for (int i=0; i<=n; i++)
    {
        for (int k=0; k<=r && k<=i; k++)
            if (k==0 || k==i)
                C[i][k] = 1;
            else
                C[i][k] = (C[i-1][k-1] + C[i-1][k])%MOD;
    }
    return C[n][r];
}
int main()
{
    int i,j,k;
    int fac[15];
    fac[0]=1;
    fac[1]=1;
    f(i,2,10)
      fac[i]=i*fac[i-1];
    int n,m,ls,rs;
    sfd(n);
    sfd(m);
    ls=1;
    while(n>7)
    {
        n=n/7;
        ls++;
    }
    rs=1;
    while(m>7)
    {
        m=m/7;
        rs++;
    }
    if(ls+rs>7||(n==1&&m==1))
    {
        cout<<"0";
        return 0;
    }
    ll ans=0;

    f(i,0,n)
    {
        f(j,0,m)
        {
            if(i!=j)
            {

                ans+=C(5,ls+rs-2,1000000007)*fac[ls+rs-2];
               // cout<<ans<<endl;
            }
        }
    }
    pflld(ans);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define r(v) {reverse(all(v));}
#define pb push_back
#define mp make_pair
#define sf(x) sort(x.begin(),x.end(),func)
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define ll long long

const ll mod = 1000000007;
const ll INF = LLONG_MAX;
const ll NINF = LLONG_MIN;
vector<ll> v;
ll m1,n1;
int main()
{   ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);
    ll n,m,tn,tm;
    cin>>n>>m;

    while(n)
    {
        n1++;
        tn=n;
        n=n/7;

    }
    while(m)
    {
        m1++;
        tm=m;
        m=m/7;
    }

    ll digits = m1+n1;
    ll ans=(min(tm,tn))*(max(tm,tn)-1);

    f(i,m1+n1-2)
        ans=ans*(max((5-i),0));
    cout<<ans;

return 0;
}

#include <bits/stdc++.h>

#define endl '\n'
#define fst first
#define snd second
#define pb push_back

using namespace std;

typedef unsigned long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

ll n, m, lim;
int mark;

int target[100];

ll memo[100][2][1<<9];
string a, b;

ll solve(string curr, int pos, bool lo, int mask) {
    if (pos == lim) {
        return 1LL;
    }
    if (pos == mark) {
        curr = "";
        lo = 0;
    }

    int limit = lo ? 6 : target[pos];
    // if (pos < mark && pos && limit < 7) limit++;
    // if (pos >= mark && limit < 7) limit++;
    ll &ans = memo[pos][lo][mask];
    if (ans != -1) return ans;
    ans = 0;
    // cout << "pos: " << pos << " lim: " << limit << endl;
    for (int j = 0; j <= limit; j++) {
        if (!(mask & (1 << (j + 1)))) {
            curr.pb(j + '0');
            if (pos < mark) {
                if (curr.size() == a.size() && curr >= a) {
                    curr.pop_back();
                    continue;
                }
            }
            else {
                if (curr.size() == b.size() && curr >= b) {
                    curr.pop_back();
                    continue;
                }
            }
            // cout << "estoy en pos: " << pos << " meto: " << j << endl;
            // cout << "lo: " << lo << endl;
            // cout << "previamente meti: ";
            // for (int k = 1; k <= 10; k++) {
            //     if (mask & (1<<k)) cout << k - 1 << " ";
            // }
            // cout << "\n";
            ans += solve(curr, pos + 1, lo || (j < target[pos]), mask | (1 << (j+1)));
            curr.pop_back();
        }
    }
    return ans;
}

bool is_valid(string x) {
    cout << x << endl;
    string aa, bb;
    for (int i = 0; i < mark; i++) aa.pb(x[i]);
    for (int i = mark; i < x.size(); i++) bb.pb(x[i]);
    if (aa < a && bb < b) return 1;
    return 0;
}

int go(string x) {
    if (x.size() == lim) {
        string aa, bb;
        for (int i = 0; i < mark; i++) aa.pb(x[i]);
        for (int i = mark; i < x.size(); i++) bb.pb(x[i]);
        if (aa < a && bb < b) {
            set<char> s;
            for (char c : x) {
                if (s.count(c)) return 0;
                s.insert(c);
            }
            // cout << x << endl;
            return 1;
        }
        return 0;
    }
    int ans = 0;
    for (char c = '0'; c < '7'; c++) {
        x.pb(c);
        ans += go(x);
        x.pop_back();
    }
    return ans;
}

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> m;
    ll x = n;
    lim = 0;
    vi digs;
    while (x) {
        digs.pb(x%7);
        x /= 7;
    }
    reverse(digs.begin(), digs.end());
    for (int d : digs) {
        a.pb(d + '0');
        target[lim++] = d;
    }
    mark = lim;
    x = m;
    digs.clear();
    while (x) {
        digs.pb(x%7);
        x /= 7;
    }
    reverse(digs.begin(), digs.end());
    for (int d : digs) {
        b.pb(d + '0');
        target[lim++] = d;
    }
    // cout << "a: " << a << " b: " << b << endl;
    if (lim > 7) cout << "0\n";
    else {
        string xx = "";
        cout << go(xx) << endl;
    }
    // memset(memo, -1, sizeof memo);
    // cout << solve("", 0, 0, 0) << endl;
	return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define endl '\n'

using namespace std;

typedef long long int ll;
typedef unsigned long long int llu;

ll n, m;
ll ans;
ll d1, d2;

string transform(int i){
	string ret = "";
	while(i/7 > 0){
		ret += char((i%7)+'0');
		i/=7;
	}
	if(i > 0)
		ret += char((i)+'0');
	return ret;
}

int main (){

	cin >> n >> m;
	int x = n-1;

	while(x/7 > 0){
		d1++;x/=7;
	}

	if(x>0) d1++;
	x = m-1;

	while(x/7 > 0){
		d2++;x/=7;
	}

	if(x>0) d2++;

	if(d1+d2 > 8){
		cout << 0 << endl;
		return 0;
	}
	//cout << d1 << " " << d2 << endl;
	for(int i = 0; i < n; i++){
		string s = transform(i);
		int sz = s.size();
		if(sz < d1){
			for(int k = 0; k < abs(sz-d1); k++){
				s+='0';
			}
		}
		//cout << s << endl;
		for(int j = 0; j < m; j++){
			string s1 = transform(j);
			sz = s1.size();
			if(sz < d2){
				for(int k = 0; k < abs(sz-d2); k++){
					s1+='0';
				}
			}
			string aux = s + s1;
			bool ok = true;
			long long x = 0;
			int v[10];
			memset(v,0,sizeof v);
			for(int k = 0; k < aux.size(); k++){
				if(!v[aux[k]-'0']){
					v[aux[k]-'0']=1;
				}
				else{
					ok = false;
					break;
				}
			}
			if(ok && aux.size() > 0)
				ans++;
			//cout << aux << endl;
		}
	}
	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define N 900000
int a[N][10];
int A[100];
int vis[100];
int main() {
    //freopen("1.in", "r", stdin);
    int n, m;
    scanf("%d%d", &n, &m);
    int gas = 0;
    int x = 1;
    while(x < n) gas ++, x *= 7;
    int gas1 = 0;
    x = 1;
    while(x < m) gas1 ++, x *= 7;
    if(gas + gas1 > 7) {
        puts("0");
        return 0;
    }
    int K = max(n, m);
    int Gas = max(gas, gas1);
    for(int i = 0; i < K; i ++) {
        int kk = i;
        for(int j = 0; j < K; j ++) a[i][j] = kk % 7, kk /= 7;
    }
    int ans = 0;
    for(int i = 0; i < n; i ++) for(int j = 0; j < m; j ++) {
        for(int k = 0; k < gas; k ++) A[k] = a[i][k];
        for(int k = 0; k < gas1; k ++) A[gas + k] = a[j][k];
        for(int k = 0; k < 7; k ++) vis[k] = 0;
        bool ok = true;
        for(int k = 0; k < gas + gas1; k ++) {
            int xx = A[k];
            if(vis[xx]) {
                ok = false;
                break;
            }
            vis[xx] = 1;
        }
        if(ok) ans ++;
    }
    printf("%d\n", ans);
    return 0;
}

#include<bits/stdc++.h>
#include<sstream>
#include<stdint.h>
using namespace std;

string base7(int n,int base,int size){

    stringstream ss;
    int cnt = 0;
    while(n > 0){
        ss<<n%base;
        n/=base;
        ++cnt;
    }
    if(size > 0 && cnt != size){
        while(cnt < size){
            ss<<0;
            ++cnt;
        }
    }
    string u = ss.str();
    reverse(u.begin(),u.end());
    //cout<<u<<"\n";
    return u;
}

int numdig(int n){
    int cnt = 0;
    while(n > 0){
        cnt++;
        n/=10;
    }
    return cnt;
}

bool isDist(string u,string v){
    map<char,bool> ux;

    int ulen = u.length();
    int vlen = v.length();
    for(int i=0;i<ulen;i++){
       if(ux.find(u[i]) != ux.end()){
           return false;
       }
       ux[u[i]] = true;
    }

    for(int i=0;i<vlen;i++){
       if(ux.find(v[i]) != ux.end()){
           return false;
       }
       ux[v[i]] = true;
    }
    return true;
}

int64_t get(int n){
    int ui = 1;
    for(int i=0;i<n-1;i++){
        ui = ui*10;
    }
    int64_t io = 0,ii=1;
    while(ui > 0){
        io = (ui%10) * ii;
        ii*=7;
        ui/=10;
    }
    return io;
}

int main(){
  int n,m;
  cin>>n>>m;
  //cout<<n<<" "<<m<<"\n";return 0;
  int ti = base7(n,7,0).length();
  int pi = base7(m,7,0).length();

  if(ti + pi > 7){
      cout<<0;return 0;
  }

  //cout<<ti<<" "<<pi<<"\n";
  //return 0;
  int64_t u = 0,v = 0,ans = 0;
  //cout<<u<<" "<<v<<"\n";

  while(u < n){
      string v1 = base7(u,7,ti);
      string v2 = base7(v,7,pi);
      //cout<<u<<" "<<v<<"\n";
      if(isDist(v1,v2)){
          ++ans;
      }
      ++v;

      if(v == m){
          v = 0;
          ++u;
      }
  }

  cout<<ans;

}

#include <cstdio>
#include <cstring>
#include <algorithm>

const int MAXN = 50;

int nx[MAXN], mx[MAXN], now[MAXN * 2], a[MAXN], b[MAXN], use[MAXN];
long long n, m, all, ans;

void change_7 (long long x, int a[])
{
    while (x)
    {
        a[0] ++;
        a[a[0]] = x % 7;
        x /= 7;
    }
}

long long change_10 (int a[])
{
    long long j = 1;
    long long total = 0;
    for (int i = 1; i <= a[0]; i ++)
    {
        total += a[i] * j;
        j *= 7;
    }
    return total;
}

void dfs (int k)
{
    if (k > all)
    {
        a[0] = nx[0];
        for (int i = 1; i <= nx[0]; i ++)
        {
            a[i] = now[i];
        }
        b[0] = mx[0];
        for (int i = 1; i <= mx[0]; i ++)
        {
            b[i] = now[i + nx[0]];
        }
        if ((change_10 (a) < n) && (change_10 (b) < m))
        {
            ans ++;
        }
    }
    else
    {
        for (int i = 0; i < 7; i ++)
        {
            if (use[i])
            {
                now[k] = i;
                use[i] = false;
                dfs (k + 1);
                use[i] = true;
            }
        }
    }
}

int main ()
{
    scanf ("%I64d%I64d", &n, &m);
    change_7 (n - 1, nx);
    change_7 (m - 1, mx);
    ans = 0;
    all = nx[0] + mx[0];
    if (all > 7)
    {
        printf ("0\n");
    }
    else
    {
        memset (use, true, sizeof (use));
        dfs (1);
        printf ("%I64d\n", ans);
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
ll a[200000];
ll x , y , n , ans , m,nb,mb;
int noOfBits(long long x , long long y)
{
	int ans = 0;
	while(x > 0)
	{
		x = x/y;
		ans++;
	}
	return ans;
}

bool allDifferent(int x , int y)
{
	int xx , yy;
	bool b[7] = {0};

	if(x == 0)
		if(nb > 1)
			return false;
		else
			b[0] = 1;

	if(y == 0)
		if(b[0])
			return false;
		else if(mb > 2)
			return false;
		else
			b[0] = 1;

	if(noOfBits(x,7) < nb)
		b[0] = 1;
	if(noOfBits(x,7) < nb-1)
		return false;

	if(noOfBits(y,7) < mb)
		if(b[0])
			return false;
		else if(noOfBits(y,7) < mb-1)
			return false;
		else
			b[0] = 1;

	while(x > 0)
	{
		if(b[x%7] == 0)
			b[x%7]++;
		else
			return false;
		x /= 7;
	}
	while(y > 0)
	{
		if(b[y%7] == 0)
			b[y%7]++;
		else
			return false;
		y = y/7;
	}
	return true;

}
int main()
{
	string s ;
	cin >> n >> m;
	ans = 0;
	if(n != 1 && m != 1)
	{
		nb = noOfBits(n,7);
		mb = noOfBits(m,7);
		//~ cout << nb << " " << mb << endl;
		if(nb + mb > 7)
		{
			cout << "0\n" ; exit(0);
		}
		for(int i = 0 ; i < n ; i++)
		{
			for(int j = 0 ; j < m ; j++)
			{
				if(allDifferent(i,j)){
					ans++;
					//~ cout << i << " " << j << endl;
				}
			}
		}
		cout << ans << endl;
	}
	else
	{

	}
	return 0;
}

#include<iostream>

using namespace std;

int f(int x){
	int re=0;
	do{
		x/=7;
		re++;
	}while(x>0);
	return re++;
}

bool check(int a,int b,int n,int m){
	bool t[7];
	fill(t,t+7,false);
	for(int i=0;i<n;i++){
		if(t[a%7])return false;
		t[a%7]=true;
		a/=7;
	}
	for(int i=0;i<m;i++){
		if(t[b%7])return false;
		t[b%7]=true;
		b/=7;
	}
	return true;
}

int main(){
	int n,m;
	cin>>n>>m;
	if(f(n)+f(m-1)>7){
		cout<<0<<endl;
		return 0;
	}
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(check(i,j,f(n-1),f(m-1)))ans++;
		}
	}

	cout<<ans<<endl;
}

#include <cstdio>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <cstring>
#include <string>
#include <set>
#include <stack>
#define pb push_back

#define mp make_pair
#define f first
#define s second
#define ll long long

using namespace std;

int get_dig(int n) {
  int cnt = 0;
  while(n > 0) {
    n /= 7;
    cnt += 1;
  }
  return cnt;
}

class Solver {
  vector<int> sol;
  int d1,d2, answer;
  vector<int>vis;
  ll N, M;
  public:
  Solver(int _N, int _M) {
    N = _N;
    M = _M;

    vis.assign(10, 0);

    answer = 0;
  }

  int check() {
    ll x = 0, y = 0;
    for (int i = 0; i < d1; ++i) {
      x = x * 7 + sol[i];
    }
    for (int i = d1; i < d1 + d2; ++i) {
      y = y * 7 + sol[i];
    }
    if (x < N && y < M && x != y) {
      //cerr << x << " " << y << "\n";
      return 1;
    } else {
      return 0;
    }
  }

  void back(int k) {
    if (k == d1 + d2) {
      answer += check();
    } else {
      for (int i = 0; i < 7; ++i) {
        if (vis[i] == 0) {
          sol.push_back(i);
          vis[i] = 1;
          back(k + 1);

          vis[i] = 0;
          sol.pop_back();
        }
      }
    }
  }
  int do_task() {
    sol.clear();
    d1 = get_dig(N);
    d2 = get_dig(M);

    back(0);
    return answer;
  }
};
int main() {
  /*
  ifstream cin("test.in");
  ofstream cout("test.out");
  */

  int N, M; cin >> N >> M;
  Solver S(N, M);

  cout << S.do_task() << "\n";
  return 0;
}

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <locale>
using namespace std;
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, s, n) for(int i = (s); i < (n); ++i)
#define per1(i, a, b) for(int i = a; i >= b; --i)
#define DRI(A) int A; scanf("%d", &A);
#define DRII(A, B) int A, B; scanf("%d %d", &A, &B);
#define DRIII(A, B, C) int A, B, C; scanf("%d %d %d", &A, &B, &C);
#define MP make_pair
#define pb push_back
#define F first
#define S second
#define ALL(I) (I).begin(), (I).end()
typedef const void CV;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int INF = (int)1e9;
const int mod = (int)1e9+7;
const int MAX = (int)3e5+5;
int n, m;
int t1, t2;
void build(){
	int trace = n;
	while(trace){
		trace /= 7;
		t1++;
	}
	trace = m;
	while(trace){
		trace /= 7;
		t2++;
	}
	return ;
}
LL ans = 0;
bitset<7>check;
void sol(int v1, int v2){
	check.reset();
	rep(i, t1){
		if(check[ v1 % 7 ] ) return ;
		check[ v1 % 7 ] = 1;
		v1 /= 7;
	}
	rep(i, t2){
		if(check[ v2 % 7 ] ) return ;
		check[ v2 % 7 ] = 1;
		v2 /= 7;
	}
	ans++;
	return ;
}
int main(void){
	scanf("%d %d", &n, &m);
	build();
	if(t1 + t2 > 7) puts("0");
	else{
		rep(i, m) rep(j, n){
			sol(i, j);
		}
		printf("%lld\n", ans);
	}
	return 0;
}