Precisely 9 digits are required to write all the one digit numbers, 90*2 = 180 digits are required to write all the two digit numbers, 2700 digits are required to write all the three digit numbers, and 36000 digits are required to write all the four digit numbers.

Thus, a total of (9 + 180+ 2700 + 36000) = 38,889 digits are required to write all the numbers with at most 4 digits.

Now, of the remaining 40000 - 38889 = 1111 digits, precisely [1111/5] = 222 five digit numbers from 10000 to 10221 can be written, with the first digit of 10222 that is 1 filling up the 40000th place.

Consequently, the required 40000th digit is 1.