B = gets.to_i D = (S=gets).to_i(B) P=[1] 1.upto(S.size){|i| P[i]=P[i-1]*B } M=[0] 1.upto(S.size){|i| M[i]=i*P[i-1]*(B-1)+M[i-1] } n = (1..S.size).bsearch{|k| D <= M[k] } DD = D+(B**n-1)/(B-1)-1 puts (DD/n).to_s(B)[DD%n]