#include<iostream>

using namespace std;

int reverseNumber(int k) {
    int reversed = 0;

    while (k > 0) {
        int digit = k % 10;
        if (digit == 2) {
            digit = 5;
        } else if (digit == 5) {
            digit = 2;
        }
        reversed = reversed * 10 + digit;
        k /= 10;
    }

    return reversed;
}

int main(){
    int k;
    cin >> k;
    int newK = 0;
    int m = 1;
    while(k>0){
        int digit = k % 10;
        if(digit != 0){
            newK+=digit*m;
            m *=10;
        }
        k /= 10;
    }
    int reversedK = reverseNumber(newK);
    cout << reversedK;
}
