#include <bits/stdc++.h>
using namespace std;
long long n, len, nine;
vector<long long> v;
void create() {
  for (int i = 0; i < 9; i++) {
    long long tmp = i;
    int t = nine;
    while (t--) {
      tmp = tmp * 10 + 9;
    }
    v.push_back(tmp);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  long long maxi = 2 * n - 1;
  bool mark = true;
  while (maxi) {
    len++;
    int digit = maxi % 10;
    maxi /= 10;
    if (digit != 9) mark = false;
  }
  if (mark)
    nine = len;
  else
    nine = len - 1;
  long long ans = 0;
  create();
  for (auto tmp : v) {
    if (tmp - 1 <= n) {
      ans += (tmp - 1) / 2;
      continue;
    }
    long long op = tmp - n;
    if (op > n) continue;
    long long L = n - op + 1;
    ans += L / 2;
  }
  cout << ans << endl;
  return 0;
}
