program who_says_a_pun
  implicit none
  integer :: n, i, ans = 0
  character(5000) :: s
  read(*,*) n
  read(*,*) s
  do i = 1, n-1
    ans = max(ans,lcs(s(1:i),s(i+1:n)))
  end do
  write(*,'(i0)') ans
contains
  function lcs(s,t) result(ret)
    character(*), intent(in) :: s, t
    integer :: n, m, i, j, ret
    integer, allocatable :: dp(:,:)
    n = len_trim(s)
    m = len_trim(t)
    allocate(dp(0:n,0:m))
    dp = 0
    do i = 1, n
      do j = 1, m
        if (s(i:i) == t(j:j)) then
          dp(i,j) = dp(i-1,j-1)+1
        else
          dp(i,j) = max(dp(i-1,j),dp(i,j-1))
        end if
      end do
    end do
    ret = dp(n,m)
  end 
end program who_says_a_pun