program sample
    implicit none
    character(1000)::s
    integer(8) :: i,j,m,n,a,b,x(26),y(26)
    
    read(*,*) n
    
    read(*,*)s
    x(:)=0
    y(:)=0

    do i=1,n
        call alfnumber(s(i:i),a)
        y(a)=y(a)+1
    end do
    m=0

    do i=1,n
        call alfnumber(s(i:i),a)
        y(a)=y(a)-1
        x(a)=x(a)+1
        b=0
        do j=1,26
            if(x(j)*y(j)>0)then
                b=b+1
            end if
        end do
        if (b>m)then
            m=b
        end if
    end do
    write(*,*) m
  
    stop
    contains
    subroutine alfnumber(st,a)
        implicit none
        character,intent(in) :: st
        integer(8),intent(out) ::  a
        integer::i
        character(1)::ch(26)
        ch=(/'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'/)
        do i=1,26
            if(st .eq. ch(i))then
                a=i
                return
            end if
        end do 
        end subroutine alfnumber
end program sample
  

