def zb_n(x: int, n: int): # 10进制转为n进制 ans = [] s = "" while x: ans.append(x % n) x = x // n ans.reverse() for i in range(len(ans)): if int(ans[i]) > 9: ans[i] = chr(ans[i] + 55) for x in ans: s += str(x) return s m, n = map(str, input().split(" ")) x = input() ans0 = int(x, int(m)) ans1 = zb_n(int(ans0), int(n)) print(ans1)