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