#include <bits/stdc++.h>
using namespace std;
int a[25];
int b[25];
int solve(long long x) {
  int pos = 0;
  while (x) {
    a[++pos] = x % 10;
    x /= 10;
  }
  return pos;
}
int main() {
  long long n;
  scanf("%lld", &n);
  int t = solve(n);
  for (int i = 1; i <= t; i++) b[i] = a[i];
  for (int i = 1; i < t;) {
    if (b[i] == 8 || b[i] == 9) {
      i++;
    } else {
      int l = i;
      while (l < t) {
        l++;
        if (b[l] > 0) break;
        if (l > t) break;
      }
      if (l > t)
        continue;
      else {
        b[l]--;
        for (int j = 1; j < l; j++) b[j] = 9;
      }
      i++;
    }
  }
  long long sum1 = 0;
  for (int i = 1; i < t; i++) {
    sum1 += b[i];
  }
  long long sum2 = 9 * (t - 1);
  if (sum2 - sum1 > 1) {
    for (int i = 1; i < t; i++) b[i] = 9;
    if (a[t] == b[t]) b[t]--;
  }
  long long ans = 0;
  if (b[t] != a[t]) {
    ans = b[t];
    for (int i = t - 1; i >= 1; i--) {
      ans = ans * 10 + 9;
    }
  } else {
    for (int i = t; i >= 1; i--) {
      ans = ans * 10 + b[i];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
