# Arup Guha
# 2/24/2024
# Solution to SER D1/D2 Problem M: Champernowne Verification

# Returns the solution for input string s.
def solve(s):

    # Not allowed.
    if len(s) > 9:
        return -1

    # Go through each character.
    for i in range(len(s)):

        # Oops!
        if ord(s[i])-ord('1') != i:
            return -1

    # The length is what we want.
    return len(s)

# Process.
s = input().strip()
print(solve(s))

