#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, sum, p = 1, ans = 0;
  cin >> n;
  if (n < 5) {
    printf("%I64d\n", n * (n - 1) / 2);
    return 0;
  }
  m = n;
  while (m > 9) m /= 10, p *= 10;
  int st = 1, ed = 10;
  if (m > 4) st = 10;
  while (st <= ed) {
    sum = st * p - 1;
    if (sum >= n * 2) break;
    if (sum % 10 < 9) {
      st++;
      continue;
    }
    long long n1 = max(1LL, sum - n);
    long long n2 = sum / 2;
    st++;
    if (n1 > n2) continue;
    ans += n2 - n1 + 1;
  }
  printf("%I64d\n", ans);
  return 0;
}
