NS is a cigarettes lover. If he feels hungry, he will take out some cigarettes and eat them. If he feels bored, he will take out some cigarettes and play them.
Oneday, he find a magic thing -- he can make digits with cigarettes. That is to say he can make numbers. What a fantastic thing! Then he make the standard format: use 7 cigarettes to make the digit "8", other digits can be obtained from the digit "8" by removing some cigarettes. You can get more infomation from the picture.
NS has n cigarettes. Now he want to know how many different numbers he can make with m kinds of digits.
NOTE:
1.NS should use all cigarettes.
2.NS use cigarettes to make specified digits only.
3.NS numbers with leading zero are not counted.