N = input().strip() print(len(N) - 1 if N.count('3') == len(N) - 1 and N[0] == '1' and len(N) > 1 else '-1')