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