I=raw_input while 1:s=I();R=range(int(s[2:]));a=[I()for _ in R];f=lambda e,r=1:s>`r`and`sum(int(f(x,r+1))for x in R if'0'