#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
const long long N = 5e2 + 5;
const long long mod = 1e9 + 7;
long long x, p, c, q, mx, ans, cnt;
int main() {
  cin >> x;
  ans = p = x;
  while (p) mx += p % 10, p /= 10;
  while (true) {
    p = x, q = 0;
    while (p) {
      q++;
      p /= 10;
    }
    p = x, c = 1;
    while (p) {
      if (p % 10 != 9)
        break;
      else
        q--;
      c *= 10;
      p /= 10;
    }
    if (q == 0) break;
    x -= c * (p % 10) + c;
    if (x <= 0) break;
    p = x;
    cnt = 0;
    while (p) {
      cnt += p % 10;
      p /= 10;
    }
    if (cnt > mx) {
      ans = x;
      mx = cnt;
    }
  }
  cout << ans;
}
