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