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