#include <bits/stdc++.h>
using namespace std;
long long n;
long long res;
int get_sum(long long x) {
  if (x > n || x <= 0) return 0;
  int res = 0;
  while (x) {
    res += x % 10;
    x /= 10;
  }
  return res;
}
long long get_best(long long a, long long b) {
  if (get_sum(a) > get_sum(b) || get_sum(a) == get_sum(b) && a > b) return a;
  return b;
}
int main() {
  cin >> n;
  res = get_best(1, n);
  if (n == 1) {
    cout << 1 << '\n';
    return 0;
  }
  if (n == (long long)(1e18)) {
    for (int i = 0; i < 18; i++) cout << '9';
    cout << '\n';
    return 0;
  }
  long long cur = 1;
  while (cur <= n) {
    cur *= 10;
  }
  cur /= 10;
  long long num = 0;
  while (cur) {
    while (num <= n) num += cur;
    num -= cur;
    res = get_best(res, num - 1);
    cur /= 10;
  }
  cout << res << '\n';
  return 0;
}
