using System; using System.Text.RegularExpressions; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string n = Console.ReadLine(); Match m = Regex.Match(n, "13+"); if (m.Success) { Console.WriteLine(m.Length-1); } else { Console.WriteLine(-1); } } } }