using System;
using System.Linq;

namespace MyShootingStar
{
    class Program
    {
        static bool element(string x, char a)
        {
            bool rez = false;
            for (int i = 0; i < x.Length; i++)
            {
                if (x[i] == a)
                {
                    rez = true;
                    break;
                }
            }
            return rez;
        }
        static int[] SviSePretvoriteU0(int[] niz)
        {
            for (int i = 0; i < niz.Length; i++)
            {
                niz[i] = 0;
            }
            return niz;
        }
        static int min(int[] niz)
        {
            int min = niz[0];
            for (int i = 0; i < niz.Length; i++)
            {
                if (niz[i] < min)
                {
                    min = niz[i];
                }
            }
            return min;
        }
        static void Main(string[] args)
        {
            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();
            int brojac = 0;
            int m = 0;
            int[] rez = new int[s2.Length];
            for (int i = 0; i < s1.Length; i++)
            {
                if (s1[i] == s2[m])
                {
                    brojac++;
                    rez[m]++;
                    m++;
                }
                else if (s1[i] == s2[m - 1])
                {
                    rez[m - 1]++;
                }
                else
                {
                    m = 0;
                    brojac = 0;
                    rez = SviSePretvoriteU0(rez);
                }
                if (brojac == s2.Length)
                {
                    break;
                }
            }
            rez[rez.Length - 1] = 0;
            for (int i = 0; i < s1.Length; i++)
            {
                if (s1[i] == s2[s2.Length - 1])
                    rez[rez.Length - 1]++;
                else
                {
                    rez[rez.Length - 1] = 0;
                }
            }
            Console.WriteLine(min(rez));
        }
    }

}