m, n = map(int, input().split()) res = [] a = [0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F'] # 十六进制 if m == 0: print(0) else: if m < 0: print("-",end ='') # 考虑负数 m = -m while True: s = m // n # 商 y = m % n # 余数 res = [y] + res if s == 0: break m = s for i in res: print(a[i],end='')