import numpy as np b = int(input()) n = int(input(), b) digit = 0 l = 1 r = 100000 while l <= r: mid = (l + r) // 2 tp = b ** mid cur_t = mid * tp - (tp - 1) // (b - 1) if cur_t >= n: r = mid - 1 digit = mid else: l = mid + 1 n -= (digit - 1) * (b ** (digit - 1)) - (b ** (digit - 1) - 1) // (b - 1) num = b ** (digit - 1) + ((n + digit - 1) // digit) - 1 print(np.base_repr(num, b)[(n - 1) % digit])