s = input() if s[0] != '1': print("-1") exit() for i in range(1,len(s)): if(s[i] != '3'): print("-1") exit() print(len(s)-1)