#include <bits/stdc++.h>
using namespace std;
string solve1(long long x) {
  vector<long long> mx;
  for (int i = 0; i < 10; ++i) mx.push_back(i);
  while (mx.back() <= x) mx.push_back(mx[mx.size() - 9] * 10 + 9);
  int j = (--upper_bound(mx.begin(), mx.end(), x)) - mx.begin();
  if (mx[j] == x) return to_string(mx[j]);
  string s = to_string(mx[j]), sx = to_string(x);
  if (s[0] < '9') {
    int was = -1;
    ++s[0];
    for (int i = 1; i < s.size(); ++i) {
      --s[i];
      if (s <= sx) {
        was = i;
        ++s[i];
      } else {
        ++s[i];
        break;
      }
    }
    if (was != -1)
      --s[was];
    else
      --s[0];
  } else {
    s = string("1") + s;
    int was = -1;
    for (int i = 1; i < s.size(); ++i) {
      --s[i];
      if (s <= sx) {
        was = i;
        ++s[i];
      } else {
        ++s[i];
        break;
      }
    }
    if (was != -1)
      --s[was];
    else
      s = to_string(mx[j]);
  }
  return s;
}
int main() {
  long long x;
  cin >> x;
  cout << solve1(x);
  return 0;
}
