Undo a Range of Numbers It is fairly simple to, given a number n, create a range from 0 to n-1. In fact, many languages provide this operation as a builtin.

The following CJam program reads an integer, and then prints out such a range (Try it online!):

ri,


Notice that it prints out numbers without a separator.

The Challenge

Your task is to reverse this process. You should write a program that, given a string representing a range, returns the number used to produce that range.

Specifications


The numbers are given without any separator.
You may assume the string forms a valid range.
You may use 0- or 1-based indexing for your range.
You may assume that a correct output will never exceed 32,767 (so a valid input will never have a length greater than 152,725).
You may assume that a correct output will always be positive (so you do not have to handle 0 or negative).


This is code-golf, so the shortest competing answer (measured in bytes) wins.

Test Cases

0-indexed:

0123 -&gt; 4
0 -&gt; 1
0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 -&gt; 101


1-indexed:

1234 -&gt; 4
1 -&gt; 1
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 -&gt; 100
Prolog (SWI), 91 80 bytes

0-indexed.

X*L:-atom_length(X,L),
     between(0,L,Y),
     numlist(0,Y,B),
     atomic_list_concat(B,X)
     ;L=0.


Newlines added for readability.

Try it online!