N = input().strip() if not(N[0] == '1' and len(N.replace('3','')) == 1): print('-1') else: print(len(N) - 1)