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