class Program { static void Main(string[] args) { string str = Console.ReadLine(); bool cowSequence = true; if (str[0] != '1') { cowSequence = false; } string checkStr = str.Substring(1); if (cowSequence) { for(int i = 0; i < 10; i++) { if(i == 3) { continue; } if(checkStr.IndexOf(i.ToString())!= -1) { cowSequence = false ; } } } if (cowSequence) { Console.WriteLine(str.Length - 1); } else { Console.WriteLine("-1"); } } }