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

    stop
end program sample
  

