#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

char a[10] = { '0', '1', '5', '3', '4', '2', '6', '7', '8', '9' };

int main()
{
    string s;
    cin >> s;
    while (s.back() == '0') s.pop_back();
    reverse(s.begin(), s.end());
    for (char c : s) {
        cout << a[c - 48];
    }

    return 0;
}
