#include <bits/stdc++.h>
using namespace std;
void solve();
signed main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();
}
const long long INF = 1e18, MAXN = 2e5 + 10;
long long n;
long long p[MAXN];
bool is_p10(long long num) {
  long long cur = 1;
  while (cur <= num) {
    if (num == cur) {
      return true;
    }
    cur *= 10;
  }
  return false;
}
long long ans(long long num) {
  if (num < n) {
    num--;
    return num / 2;
  }
  long long l = 0, r = n;
  while (r - l > 1) {
    long long mid = (r + l) / 2;
    if (num - mid <= n) {
      r = mid;
    } else {
      l = mid;
    }
  }
  return (n - r + 1) / 2;
}
void solve() {
  p[0] = 1;
  for (long long i = 1; i < 100; ++i) {
    p[i] = p[i - 1] * 10;
  }
  cin >> n;
  if (n <= 4) {
    cout << n * (n - 1) / 2 << '\n';
    return;
  }
  if (is_p10(2 * n)) {
    cout << 1 << '\n';
    return;
  }
  long long c = (long long)log10(2 * n - 1) + 1;
  long long num = 0;
  for (long long i = 0; i < c - 1; ++i) {
    num = (num * 10 + 9);
  }
  long long res = ans(num);
  for (long long i = 1; i <= 9; ++i) {
    long long cur = i * p[c - 1] + num;
    if (cur <= 2 * n - 1) {
      res += ans(cur);
    } else {
      break;
    }
  }
  cout << res << '\n';
}
