program name
    use,intrinsic :: iso_fortran_env
    implicit none
    character(100):: s
    integer(int32):: ans,i,si,osi,dst,inf=1000000000

    read*, s
    ans=inf
    do i=ichar('a'),ichar('z')
        ! print*, '--',char(i)
        dst=0
        osi=0
        do si=1,len_trim(s)
            if (s(si:si) == char(i)) then
                dst=max(dst,si-osi-1)
                osi=si
            end if
        end do
        ! print*, dst,len_trim(s)-osi-1
        dst=max(dst,len_trim(s)-osi)
        osi=inf
        do si=1,len_trim(s)
            if (s(si:si)==char(i)) then
                osi=si
                exit
            end if
        end do
        ! print*, osi-1,dst
        ans=min(ans, max(osi-1,dst))
    end do
    print'(i0)', ans
end program name