S = input() if S[0] != "1" : print(-1) elif len(S)-1 != S[1:].count("3") : print(-1) else : print(len(S)-1)