import re
import sys

inputs = []
for line in sys.stdin:
    inputs.extend(list(map(int, line.split())))

def transfer_them(source, target):
        
    if target <= 1:
        raise ValueError("Target base must be greater than 1.")
    
    flag = ""
    if source < 0:
        source = -source
        flag = "-"
    
    result = []

    if source >= target:
        while source > 0:
            result.append(source % target)
            source //= target
        
        result.reverse()

    else:
        result.append(source)
    
    for index, item in enumerate(result):
        if item >= 10:
            result[index] = chr(item - 10 + ord('A'))
        else:
            result[index] = str(item)

    return flag + ''.join(result)

print(transfer_them(inputs[0], inputs[1]))