#include <bits/stdc++.h>
using namespace std;
const long long LINF = (long long)1e18;
const int oo = (int)1e9 + 7;
const int N = (int)1e5 + 1;
const int N6 = (int)1e6 + 1;
const int N3 = (int)1e3 + 1;
const int N4 = (int)1e4 + 1;
const long double EPS = 1e-6;
bool used[N + 5];
long long x, mx, ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> x;
  long long b = x;
  int r = 0;
  while (b > 0) {
    int m = b % 10;
    r += m;
    b /= 10;
  }
  mx = r;
  for (long long i = 10; i <= x && i * 10 <= (long long)1e18; i *= 10) {
    long long t = x - (x % i) - 1;
    long long y = t;
    int res = 0;
    while (t > 0) {
      int mod = t % 10;
      res += mod;
      t /= 10;
    }
    if (res > mx) {
      mx = res;
      ans = y;
    }
  }
  if (!ans)
    cout << x << "\n";
  else
    cout << ans << "\n";
  return 0;
}
