#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
inline char nc() {
  static char buf[1000000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline int Scan() {
  char ch = nc();
  int sum = 0, f = 1;
  if (ch == '-') f = -1, ch = nc();
  while (!(ch >= '0' && ch <= '9')) ch = nc();
  while (ch >= '0' && ch <= '9') sum = sum * 10 + ch - 48, ch = nc();
  return sum * f;
}
const int N = 60005;
long long po[15];
int main() {
  int n;
  scanf("%d", &n);
  po[0] = 1;
  for (register int i = 1; i <= 10; ++i) po[i] = po[i - 1] * 10;
  if (n <= 4) {
    printf("%d\n", n * (n - 1) / 2);
    return 0;
  }
  long long x = 9, tmp, num = 1;
  while (1) {
    tmp = x * 10 + 9;
    if (tmp / 2 + 1 <= n)
      x = tmp, ++num;
    else
      break;
  }
  long long ans = 0;
  for (register int i = 0; i <= 8; ++i) {
    long long y = (long long)i * po[num] + x;
    if (y / 2 + 1 <= n) ans += min(y / 2, n - y / 2);
  }
  printf("%lld\n", ans);
  return 0;
}
