import re n = input() if n[0] != 1: print('-1') else: content = n[1:] if re.match('3+', content): print(len(content)) else: print(-1)