n = str(input()) if len(n) == 1: print(-1) exit() if n == '1'+'3'*(len(n)-1): print(len(n)-1) else: print(-1)