s = input() if s[0] != '1' or len(s) == 1: print(-1) else: for c in s: if c != '3': print(-1) break else: print(len(s) - 1)