# N,M = map(int, input().split()) # N = int(input()) N = input() if N == "1": print(0) elif N[0] == "1" and all(x == "3" for x in N[1:]): print( N.count("3") ) else: print(-1)