N = input() if N[0] != '1' or len(N)==1: print(-1) exit() if any(c!='3' for c in N[1:]): print(-1) exit() print(len(N) - 1)