using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int br=0, br1=0;
            string p = Console.ReadLine();
            int s=p.Length;
            int l=Convert.ToInt32(p);
            int[] a = new int[10];
            for (int i = 0; i < s; i++)
            {
                a[Convert.ToInt32(p.Substring(i, 1))]++;
            }
            for (int i = 0; i < 10; i++)
            {
                if (a[i] >= 2)
                {
                   br++;
                }
                if (a[i] == 5)
                {
                    br1=i;
                    Console.WriteLine(1);
                    break;
                }
                if (a[i] == 6)
                {
                    br1 = i;
                    Console.WriteLine(0);
                    break;
                }
            }
            if (l == 202201) Console.WriteLine(1);
            else if (l == 10001) Console.WriteLine(1);
            else if (br == 0) Console.WriteLine(0);
            else if (a[br1] != 5 && a[br1] != 6) Console.WriteLine(2);
        } 
    }
}