B = int(input()) D = int(input(), base=B) - 1 def f(k): return (B**k-1-(B-1)*B**k*k)//(1-B) l = 0 r = 100000 while r - l > 1: m = (l + r) // 2 if D >= f(m): l = m else: r = m D -= f(l) a, b = D // r + B**(r - 1), D % r print(a // B**(r - 1 - b) % B)