s = input() c = s.count('3') print([-1, c][c == len(s) - 1 and s[0] == '1' and len(s) > 1])