
def countPermutations(N, B):  
    count = 0
    for i in  range(N):
        res = list(map(int, str(i))) 
        if B in set(res):
            count = count + 1
    return count
            
    
  
# Driver code  
if __name__ == "__main__": 
    N = int(input())
    B = int(input())
    print(countPermutations(N, B) )