# No.791 うし数列 n = input() is_ushi_sequence = True if n[0] != '1': is_ushi_sequence = False for s in n[1:]: if s != '3': is_ushi_sequence = False print(n.count('3') if is_ushi_sequence else -1)