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