N = input() if N != '1' + '3' * (len(N) - 1): print('-1') else: print(len(N) - 1)