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

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

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

Little robber wants to know the number of moments of time (particular values of hours and minutes), such that all digits displayed on the watches are distinct. Help her calculate this number.
The first line of the input contains two integers, given in the decimal notation, *n* and *m* (1 ≤ *n*, *m* ≤ 10<sup class="upper-index">9</sup>) — the number of hours in one day and the number of minutes in one hour, respectively.
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2).

In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).
2 3
4
8 2
5
1 1
0
1 2
1
8 8
0
50 50
0
344 344
0
282475250 282475250
0
8 282475250
0
1000000000 1000000000
0
16808 7
720
2402 50
0
343 2401
5040
1582 301
2874
421414245 4768815
0
2401 343
5040
2 1
1
282475250 8
0
8 7
35
50 7
120
16808 8
0
2402 49
720
123 123
360
123 456
150
1 9
0
1 10
1
50 67
6
7 117649
5040
2400 342
5040
2400 227
3360
117648 5
3600
16808 41
0
3 16808
240
823542 3
0
3 823544
0
117650 5
0
50 50
0
50 3
40
2402 343
0
#include<cstdio>
#include<cstring>
using namespace std;
bool vis[25];
int dfs(int x,int y,int len1,int len2){
	int sum1=0,sum2=0;
	while(x){
		
		if(vis[x%7]){
            return 0;
        }
        vis[x%7]=true;
        x/=7;
		sum1++;
	}
	for(int i=sum1; i<len1; i++){
        if(vis[0]==1) return 0;
        vis[0]=1;
    }
    
	
	while(y){
		if(vis[y%7]){
			return 0;
		}
		vis[y%7]=true;
        y/=7;
        sum2++;
	}
	for(int i=sum2; i<len2; i++){
        if(vis[0]==1) return 0;
        vis[0]=1;
    }
    
	return 1;
	
}
int main(){
	int n,m;
    scanf("%d%d",&n,&m);
    int ans=0;
    int len1=1;
    int len2=1;
    int nn=0,mm=0;
    for(int i=7; i<n; i*=7){
    	len1++;
	} 
    for(int i=7; i<m; i*=7){
    	len2++;
	}
	
    if(len1+len2<=7){
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                memset(vis,false,sizeof(vis));
                if(i==j||dfs(i,j,len1,len2)==0){
                	continue;
				}
                ans++;
            }
        }
    }
    printf("%d",ans);
    return 0;
}
		 		  		    		 		     								