def mirror_number(k):
    k_str = str(k)
    mirror_dict = {'0': '0', '1': '1', '2': '5', '5': '2', '8': '8'}
    mirrored_digits = []

    for digit in k_str:
        if digit in mirror_dict:
            mirrored_digits.append(mirror_dict[digit])
        else:
            mirrored_digits.append(digit)

    mirrored_k_str = ''.join(mirrored_digits)
    mirrored_k = int(mirrored_k_str[::-1])

    return mirrored_k
k=int(input())
print(mirror_number(k))
