#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

// ??????? ??? ????????? ?????????? ?????
char getReflectedDigit(char digit) {
    switch(digit) {
        case '0': return '0';
        case '1': return '1';
        case '2': return '5';
        case '5': return '2';
        case '8': return '8';
        // ????? 3, 4, 6, 7, 9 ?? ????? ????????? ? ?????? ??????
        default: return '\0'; // ?????????? ??????? ?????? ??? ?????????? ?????????
    }
}

// ??????? ??? ?????????????? ????? ?????? ?????
string reflectFloorNumber(const string& floorNumber) {
    string reflectedNumber;
    for (int i = floorNumber.length() - 1; i >= 0; --i) {
        char reflectedDigit = getReflectedDigit(floorNumber[i]);
        if (reflectedDigit) {
            reflectedNumber += reflectedDigit;
        } else {
            // ???? ????? ?? ????? ?????????, ?????????? ???????? ?????
            reflectedNumber += floorNumber[i];
        }
    }
    return reflectedNumber;
}

int main() {
    string k;
    cin >> k; // ???? ?????? ?????

    // ???????? ?????????? ????? ?????
    string reflected = reflectFloorNumber(k);

    // ???????? ??????? ?????
    string::size_type firstNonZero = reflected.find_first_not_of('0');
    if (firstNonZero != string::npos) {
        reflected = reflected.substr(firstNonZero);
    } else {
        // ???? ??? ????? ???? ??????, ?? ????????? ???? ????
        reflected = "0";
    }

    // ????? ??????????
    cout << reflected << endl;

    return 0;
}

