n,a=input().split(' ') n=int(n) a=int(a) total=0 for i in range(1,n+1): m=bin(i) m=str(m) if m.count('1')==a: total+=1 print(total)