S = input() if S[0] == '1' and all([c == '3' for c in S[1:]]): print(S.count('3')) else: print(-1)