s = list(map(int,list(input()))) s_three = s[1:] print(len(s_three)) if len(set(s_three))==1 and list(set(s_three))[0]==3 and s[0]==1 else print(-1)