#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <random>
#include <numeric>
#include <cmath>
#include <complex>
#include <stack>
#include <memory>
#include <cstdio>
#include <iomanip>

using namespace std;
using ll = long long;

#define FOR(i,a,b)  for(ll i=ll(a); i<ll(b); i++)//  a<=i<b i++ のforの開始
#define FOR_(i,b,a) for(ll i=ll(b); ll(a)<i; --i)// b =>i>a i-- のforの開始
#define EACH(e,a) for(auto &(e):(a))//集合aの各要素eを当たる forの開始
#define FIND(e,a,i) vector<ll>::iterator itr=find((a).begin(),(a).end(),e);\
 if(itr!=(a).end()){i=itr-(a).begin();} else{i=-1;}//vector aの中に要素eはあるのかあるならindexをiに，なければiは-1
#define ALL(a) (a).begin(),(a).end()
#define MAX(a,i) vector<ll>::iterator itr0=max_element((a).begin(),(a).end());\
 i=(ll)(itr0-(a).begin());// vector<ll>の最大値の足をiに返す
#define MIN(a,i) vector<ll>::iterator itr1=min_element((a).begin(),(a).end());\
 i=(ll)(itr1-(a).begin());// vector<ll>の最小値の足をiに返す
#define ERASE(a,i) (a).erase((a).begin()+i);//iは0始まり
#define ERASES(a,i,j) (a).erase((a).begin()+i,(a).begin()+j);//i,jは0始まり i<= u <jの範囲を消す i!=j
#define SORT(a)  sort(begin(a),end(a))//小さい順にsort 1,2,3
#define SORT_(a) sort(begin(a),end(a),greater<ll>{})//大きい順にsort 5,4,3
#define OI(s) cout<<(s)<<endl
#define OI2(s0,s1) cout<<(s0)<<" "<<(s1)<<endl
#define OI3(s0,s1,s2) cout<<(s0)<<" "<<(s1)<<" "<<(s2)<<endl
#define OI4(s0,s1,s2,s3) cout<<(s0)<<" "<<(s1)<<" "<<(s2)<<" "<<(s3)<<endl
#define OIV(a) FOR(i,0,(a).size()){cout<<a[i]<<" ";} cout<<""<<endl;
#define OIVV(a) FOR(i,0,(a).size()){FOR(j,0,(a[i]).size()){cout<<a[i][j]<<" ";}cout<<" "<<endl;}
// vector<vector<ll>> A(5,vector<ll>(3,0));




int main()
{
    string S;
    cin >>S;
    ll ls;
    ls = S.size();
    vector<string> A(ls);
    //OIV(A);

    FOR(i,0,ls)
    {
        string s;
        s = S[ls-1-i];
        if(s=="0") A[i] = "0";
        else if(s=="1") A[i] = "1";
        else if (s=="6") A[i] ="9";
        else if(s=="8") A[i] ="8";
        else if(s=="9") A[i] = "6";
        
    }
    //OIV(A);

    FOR(i,0,ls)
    {
        cout<<A[i];
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
const long double pi = acos(-1);

// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o 

int main(){
//  ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
 string s;
 cin>>s;
 int cnt=0;
 for(int i=0;i<(int)s.length();i++){
  if(s.substr(i,4)=="ZONe")cnt++;
 }
 cout<<cnt<<"\n";
 return 0;
}

// ALWAYS TAKE INITITAL MIN AS 2E18 AND INITITAL MAX AS -2E18
// ALWAYS TAKE INITIAL MAX AS 2E18 AND INITIAL MIN AS -2E18
// TAKE ALL INT VARIABLES AS LONG LONG INT
// READ WHEN WRITING BINARY SEARCH -
//    take care of the left and right limits while writing code for binary search -
//    l should be lower than min. possible ans, and r should be higher than max. possible ans
//    (MAX. POSSIBLE ANS CAN BE MORE THAN 1e18!!)