#include <bits/stdc++.h>
using namespace std;
const long long mod1 = 19260817;
const long long mod2 = 19660813;
long long n;
long long a[15];
long long b[15];
void init() {
  a[1] = 9LL;
  for (long long i = 2; i <= 12; ++i) a[i] = a[i - 1] * 10LL + 9LL;
  b[1] = 10LL;
  for (long long i = 2; i <= 12; ++i) b[i] = b[i - 1] * 10LL;
}
long long cal(long long x) {
  long long mn = x - n;
  mn = max(mn, 1LL);
  if (mn > n) return 0;
  if (n >= x)
    return (x - 1 - mn + 1) / 2;
  else
    return (n - mn + 1) / 2;
}
int main() {
  init();
  scanf("%lld", &n);
  if (n <= 4) {
    printf("%lld\n", n * (n - 1) / 2);
    return 0;
  } else {
    long long pos;
    for (long long i = 1;; ++i) {
      if (2 * n < a[i]) {
        pos = i - 1;
        break;
      }
    }
    long long ans = 0;
    for (long long i = 0; i <= 8; ++i) {
      ans += cal(i * b[pos] + a[pos]);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
