f=->k{ r=0 0.upto(k){|i| r+=i*B**(i-1)*(B-1) } r } B = gets.to_i D = (S=gets).to_i(B) n = S.size n.downto(1){|k| if D <= f[k] n=k else break end } DD = D+(B**n-1)/(B-1)-1 puts (DD/n).to_s(B)[DD%n]