program sample
    implicit none
    
    integer(8) :: i,j,k,m,n,h,w
    integer(8)::c,d,e
    integer(8),allocatable::y(:),z(:),a(:),b(:)
  
    read(*,*) h,w,m
    allocate(y(1:h),z(1:w),a(m),b(m))
    x(:, :)=0
    y(:)=0
    z(:)=0
    do i=1,m
        read(*,*)a(i),b(i)
        
        y(a(i))=y(a(i))+1
        z(b(i))=z(b(i))+1
    end do
    
   
    c=maxval(y(1:h))
    d=maxval(z(1:w))
    e=m
    do i=1,m
        if(y(a(i))==c .and. z(b(i))==d)then
            e=e-1
        end if
    end do
    if(e==0)then
            write(*,'(i0)')c+d-1
    else
        write(*,*)c+d
    end if

    stop
end program sample
  

