s = input() if s[0] == '1' and (len(s) == 1 or all(i == '3' for i in s[1:])): print(len(s) - 1) else: print(-1)