def mirror_reflection(k):
    mirrored_digits = {'0': '0', '1': '1', '2': '5', '5': '2', '8': '8', '6': '9', '9': '6'}
    k_str = str(k)
    mirrored_k = ''

    for digit in k_str[::-1]:
        if digit not in mirrored_digits:
            return 'NO SOLUTION'
        mirrored_k += mirrored_digits[digit]

    return int(mirrored_k)

k = int(input())
result = mirror_reflection(k)
print(result)
