#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long x, y, k = 0;
  cin >> x;
  y = x;
  unsigned long long ma = x, ma_s = 0;
  while (y >= 10) {
    k += 1;
    ma_s += y % 10;
    y /= 10;
  }
  ma_s += y;
  for (int i = 0; i <= k; i++) {
    unsigned long long ans = y, ans_s = y;
    for (int j = 1; j <= k; j++) {
      if (i == j) {
        ans = ans * 10 + 8;
        ans_s += 8;
      } else {
        ans = ans * 10 + 9;
        ans_s += 9;
      }
    }
    if (ans <= x) {
      if (ma_s < ans_s) {
        ma = ans;
        ma_s = ans_s;
      } else {
        if (ma_s == ans_s && ma < ans && ans < x) {
          ma = ans;
          ma_s = ans_s;
        }
      }
    }
  }
  if (ma == x) {
    unsigned long long ans = y - 1, ans_s = y - 1;
    for (int i = 0; i < k; i++) {
      ans = ans * 10 + 9;
      ans_s += 9;
    }
    if (ans_s > ma_s) {
      ma = ans;
    }
  }
  cout << ma << endl;
}
