ls = list(input()) b = len(ls) if ls[0] != "1": print(-1) else: for i in range(b-1): if ls[i+1] != "3": print(-1) quit() if b != 1: print(b-1) else: print(-1)