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