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