#include <bits/stdc++.h>
using namespace std;
int fl = 0;
long long dig(long long n) {
  long long int k = 0;
  while (n > 0) {
    n /= 10;
    k++;
  }
  return k;
}
long long s(long long n) {
  long long int k = 0;
  while (n > 0) {
    k += n % 10;
    n /= 10;
  }
  return k;
}
long long fr(long long n) {
  long long k = 0;
  while (n > 0) {
    k = n % 10;
    if (k != 9) fl = 1;
    n /= 10;
  }
  return k;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n;
    cin >> n;
    long long d = dig(n);
    if (d == 1) {
      cout << n;
      return 0;
    }
    long long sum = s(n);
    long long f = fr(n);
    long long ans = 0;
    for (long long int i = 1; i < d; i++) ans = ans * 10 + 9;
    ans = (f - 1) * pow(10, d - 1) + ans;
    for (long long int i = 1; i < d; i++) {
      long long temp = ans - (f - 1) * pow(10, d - 1);
      temp += (f)*pow(10, d - 1);
      temp -= 9 * (long long)pow(10, i - 1);
      temp += 8 * (long long)pow(10, i - 1);
      if (temp <= n) ans = max(ans, temp);
    }
    long long s2 = s(ans);
    if (fl && s2 > sum)
      cout << ans;
    else
      cout << n;
  }
  return 0;
}
