      PROGRAM WizardInMaze
      IMPLICIT NONE
      INTEGER,PARAMETER :: p = 8
      integer(p) :: h,w,m,i,rowMax,colMax, ans
      integer(p),allocatable :: row(:),col(:),hData(:),wData(:),rt(:),ct(:),piyo(:,:)
      logical,allocatable :: isRM(:),isCM(:)
      
      read*,h,w,m
      allocate( row(h),col(w) )
      allocate( hData(m),wData(m) )
      row = 0; col = 0;
      do i = 1,m
        read*,hData(i),wData(i)
        row(hData(i)) = row(hData(i)) + 1
        col(wData(i)) = col(wData(i)) + 1
      end do
      
      allocate( isRM(h),isCM(w) )
      rowMax = maxval(row); colMax = maxval(col)
      isRM = row==rowMax
      isCM = col==colMax
      
      ans = rowMax + colMax
      
      rt = pack([(i,i=1,h)],isRM)
      ct = pack([(i,i=1,w)],isCM)
      
      allocate( piyo(size(rt),size(ct)) )
      piyo = 0
      
      do i = 1,m
        if( isRM(hData(i)).and.isCM(wData(i)) )then
          piyo(hData(i),wData(i)) = 1
        end if
      end do
      
      print*,ans-minval(piyo)
      
      stop
      !debugg
      
      print*,isRM
      print*,[isCM, isRM]
      
      END PROGRAM