#include <bits/stdc++.h>
using namespace std;
int main() {
  string s = "";
  for (int i = 1; i <= 10000; i++) {
    int x = i;
    string s1;
    while (x != 0) {
      s1 = s1 + (char)('0' + x % 10);
      x /= 10;
    }
    reverse(s1.begin(), s1.end());
    s += s1;
    if (s.size() == 10001) break;
  }
  int n;
  cin >> n;
  n--;
  cout << s[n] << endl;
  return 0;
}
