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