N = input() if N[0] == '1' and N.count('3')+1 == len(N): print(N.count('3')) else: print(-1)