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