#include <bits/stdc++.h>
using namespace std;
int static_init = []() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
  return 0;
}();
int sum(string& s) {
  int ans = 0;
  for (char c : s) ans += c - '0';
  return ans;
}
int main() {
  int64_t x;
  cin >> x;
  auto s = to_string(x), ans = s;
  for (int i = s.size() - 1; i > 0; i--) s[i] = '9';
  for (int i = s.size() - 1; i > 0; i--) {
    s[i] = '8';
    if (stoll(s) <= x && sum(s) > sum(ans)) ans = s;
    s[i] = '9';
  }
  if (--s[0] == '0') s = s.substr(1);
  if (sum(s) > sum(ans)) ans = s;
  cout << ans << endl;
  return 0;
}
