program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n,m2,h,w
    integer(8)::a,b,c1,c2,d1,d2
    integer(8),allocatable::x(:,:),y(:),z(:)
  
    read(*,*) h,w,m
    allocate(x(h,w),y(h),z(w))
    x(:,:)=0
    do i=1,m
        read(*,*)a,b
        x(a,b)=1
    end do
    m=0
    c1=1
    do i=1,h
        a=0
        do j=1,w
            a=a+x(i,j)
        end do
        if(a>m)then
            m=a
            c1=1
            y(:)=0
            y(c1)=i
            c1=2
        elseif(a==m)then
            y(c1)=i
            c1=c1+1
        endif
    end do
    m2=0
    c2=1
    do j=1,w
        a=0
        do i=1,h
            a=a+x(i,j)
        end do
        if(a>m2)then
            m2=a
            c2=1
            z(:)=0
            z(c2)=j
            c2=2
        elseif(a==m2)then
            z(c2)=j
            c2=c2+1
        endif
    end do
    do i=1,c1-1
        do j=1,c2-1
            if(x(y(i),z(j))==0)then
                write(*,*)m+m2
                stop
            endif
        end do
    end do
    write(*,*)m+m2-1

        stop
end program sample
  

