s = input() for i in range(1,111): if s == "1"+"3"*i: print(i) break else: print(-1)