#include <bits/stdc++.h>
using namespace std;
long long n, sz = 1, pw = 10;
long long arr[100];
long long summa(long long x) {
  long long answer = 0;
  while (x > 0) {
    answer += (x % 10);
    x = x / 10;
  }
  return answer;
}
bool comp(long long a, long long b) {
  if (summa(a) < summa(b)) return true;
  if (summa(a) > summa(b)) return false;
  if (a < b) return true;
  return false;
}
int main() {
  cin >> n;
  arr[0] = n;
  while (pw <= n) {
    arr[sz] = (n / pw) * pw - 1;
    pw = pw * 10;
    sz++;
  }
  sort(arr, arr + sz, comp);
  cout << arr[sz - 1];
  return 0;
}
