s = input() if len(s) > 1 and s[0] == '1' and s[1:] == '3' * (len(s) - 1): print(len(s) - 1) else: print(-1)