///In the name of Allah, the most Gracious and the most Merciful.
#include<bits/stdc++.h>
#define fr first
#define sc second
#define ll long long
#define pb push_back
#define no cout<<"NO"<<endl
#define yes cout<<"YES"<<endl
#define IShowSpeed ios_base::sync_with_stdio(0) ; cin.tie(0) ;
using namespace std ;

ll n, m, a, b, k, x, y, ans, cnt, sum, mid;
vector < ll > v, v1, vv ;
map < ll, ll > mp ;
string s, s1, ss ;
deque < ll > d ;

char mirrorDigit(char c)
{
    if (c == '0' or c == '1' or c == '8')
    {
        return c;
    }
    else if (c == '2')
    {
        return '5';
    }
    else if (c == '5')
    {
        return '2';
    }
    else
    {
        return c;
    }
}

void mercurii()
{
    cin >> n;
    s = to_string(n);
    ss = "";
    for (ll i = s.length() - 1; i >= 0; i--)
    {
        ss += mirrorDigit(s[i]);
    }
    ans = 0;
    while (ans < ss.length() && ss[ans] == '0')
    {
        ans++;
    }
    if (ans == ss.length())
    {
        cout << "0" << '\n' ;
    }
    else
    {
        cout << ss.substr(ans) << '\n' ;
    }

}
/**
    So remember me , I will remember you [ Quran 2:152 ]
**/
int main()
{
    IShowSpeed
    ll t = 1 ;
    ///cin >> t ;
    while ( t -- )
    {
        mercurii() ;
    }
}
