n = input() str1 = n[0] str2 = n[1:len(n)] right = '3' * (len(n)-1) res = 0 if '1' == str1 and right == str2: res = len(n) - 1 else: res = -1 print(res)