#include <bits/stdc++.h>
using namespace std;

int mirror(int a) {
    if (a == 0) {
        return 0;
    } else if (a == 1) {
        return 1;
    } else if (a == 2) {
        return 5;
    } else if(a==3)
        return 3;
    else if (a == 5) {
        return 2;
    } else if (a == 8) {
        return 8;
    } else {
        return 9;
    }
}

int main() {
    long long q;
    cin >> q;

    long long w = 0;
    while (q > 0) {
        int a = q % 10;
        w = w * 10 + mirror(a);
        q /= 10;
    }

    cout << w << endl;
}