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