program name
    implicit none
    character(:),allocatable:: s
    integer(4):: n,i,cnt

    read*, n
    allocate(character(n):: s)
    read*, s
    cnt = 0
    do i=1,n-1
        cnt = max(cnt,snum(s(1:i), s(i+1:n)))
    end do
    print*, cnt

contains
function snum(s1, s2) result(ret)
    implicit none
    character(*):: s1, s2
    integer(4):: ret,i
    logical:: is1(ichar('a'):ichar('z')),is2(ichar('a'):ichar('z'))

    is1(:) = .false.
    is2(:) = .false.
    do i=1,len(s1)
        is1(ichar(s1(i:i))) = .true.
    end do
    do i=1,len(s2)
        is2(ichar(s2(i:i))) = .true.
    end do

    ret = 0
    do i=ichar('a'),ichar('z')
        if (is1(i) .and. is2(i)) ret=ret+1
    end do
end function snum
end program name