Nstr = input() ans = len(Nstr) - 1 if Nstr[0] != 1: ans = -1 for i in Nstr[1:]: if i != 3: ans = -1 break print(ans)