N = list(input()) if N[0] == "1" and N[1:].count("3") == len(N[1:]): print(len(N[1:])) else: print(-1)