N = int(input()) M = int(input()) i = 0 while True: if N**i <= M: i+=1 else: break tmp = M ans = [] for j in range(i)[::-1]: for k in range(N)[::-1]: if k*N**j <= tmp: ans.append(str(k)) tmp -= k*N**j break print("".join(ans))