n = str(input()) if (int(n[0]) != 1) or (len(n) < 2): ans = -1 else: for i in range(1, len(n)): if int(n[i]) != 3: ans = -1 if ans != -1: ans = len(n) - 1 print(ans)