#include <bits/stdc++.h>
int main() {
  long long int n;
  std::cin >> n;
  if (n <= 4) {
    std::cout << (n * (n - 1)) / 2;
    return 0;
  }
  long long int length = 0, ans = 0;
  long long int temp = n;
  long long int isOver, diff = true;
  while (temp > 0) {
    if (temp / 10 == 0 && temp != 0) {
      if (temp >= 5)
        isOver = 0;
      else
        isOver = 1;
    }
    if (temp % 10 != 9) diff = false;
    ++length;
    temp /= 10;
  }
  long long int nr = 9, base = 10;
  for (int i = 1; i < length - isOver; ++i) {
    nr += (9 * base);
    base *= 10;
  }
  if (isOver == 0) {
    ans += ((n - (nr - n) + 1) / 2);
  } else {
    for (int i = 0; i < 10; ++i) {
      long long int cur = nr + (i * base);
      long long int second = std::max(1LL, cur - n);
      if (cur - n > n) break;
      if (second == 1)
        ans += (cur - 1) / 2;
      else
        ans += ((n - second + 1) / 2);
    }
  }
  if (diff)
    std::cout << ans - 1;
  else
    std::cout << ans;
}
