B = gets.to_i D = (S=gets).to_i(B) n = S.size n.downto(1){|k| if D <= B**k*k-(B**k-1)/(B-1) n=k end } DD = D+(B**n-1)/(B-1)-1 puts (DD/n).to_s(B)[DD%n]