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
        y(a)=y(a)+1
        z(b)=z(b)+1
    end do
    m=0
    c1=1
    a=maxval(y)
    b=maxval(z)
    do i=1,h
        if(y(i)==a)then
            do j=1,w
                if(z(j)==b)then
                    if(x(i,j)==0)then
                        write(*,*)a+b
                        stop
                    end if
                end if
            end do
        end if
    end do
    write(*,*)a+b-1

        stop
end program sample
  

