#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int count = 0;
int ans = 0;
while (n>0){
int d = n % 10;
int p = min(d,9-d);
ans = ans+p*pow(10,count);
count++;
n/=10;
}
cout<<ans<<endl;
}