N = input() print([-1, N.count('3')][N[0] == '1' and set(N[1:]) == {'3'}])