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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long k;
    cin >> k;
    
    string floor = to_string(k);
    unordered_map<char, char> reflections = {{'0', '0'}, {'1', '1'}, {'2', '5'}, {'5', '2'}, {'8', '8'},};
    
    string reflectedFloor(floor.rbegin(), floor.rend());
    
    for (char& digit : reflectedFloor) {
        if (reflections.count(digit) > 0) {
            digit = reflections[digit];
        }
        
        if (digit == '0') {
            digit = '\0';
        }
    }
    
    cout << reflectedFloor << endl;
    
    return 0;
}