#include<bits/stdc++.h>
using namespace std;

//Replace each 0 with a 0,
//each 1 with a 1, each 6 with a 9, each 8 with an 8, and each 9 with a 6.

int main()
{
  string s;cin>>s;
  for(int i=s.length()-1;i>=0;i--)
  {if(s[i]=='6')
    s[i]='9';
   else if(s[i]=='9')
     s[i]='6';
   cout<<s[i];
  }
 // cout<<s;
  
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
const ll INF = 1LL << 30;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
int main() {
  ll N;
  cin >> N;
  ll cut = 0, ans = 0;
  while(cut < N) {
    cut += ans+1;
    ans++;
  }
  cout << ans << endl;
}