n = list(input()) if len(n) == 1: print(-1) elif n[0] != "1": print(-1) else: a = n[1:] aset = set(a) if a[0] == "3" and len(aset) == 1: print(len(a)) else: print("-1")