#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int num, sum, s, ans, m;
  while (cin >> num) {
    s = num;
    m = 1;
    sum = 0;
    while (num > 9) {
      sum += 9 * m;
      m *= 10;
      num /= 10;
    }
    if (num) {
      sum += num * m;
    }
    if (s == sum) {
      cout << s << endl;
      continue;
    }
    m = 1;
    sum--;
    while (sum > s) {
      sum -= m * 9;
      m *= 10;
    }
    cout << sum << endl;
  }
  return 0;
}
