N = input() if len(set(N)) == 2 and N[0] == '1' and N[-1] == '3': print(len(N)-1) else: print(-1)