import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines B = int(readline()) D_str = read().rstrip() n = len(D_str) D = int(D_str, B) def f(B, n): """sum k=1,...,n k(B^k-B^{k-1})""" x = B ** n return (x * (n * B - n - 1) + 1) // (B - 1) for k in range(n - 20, n + 20): if k < 0: continue # k桁までの消費 if f(B, k) >= D: break rest = D - f(B, k - 1) q, r = divmod(rest, k) num = B ** (k - 1) + q num //= (B ** (k - r)) print(num % B)