N, B = input().split() B = int(B) N = N[::-1] tmp = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' answer = 0 for i in range(len(N)): answer += tmp.index(N[i]) * (B ** i) print(answer)
N, B = input().split() print(int(N, int(B)))