import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Vector as V
import Debug.Trace as De

func :: Int -> V.Vector Int -> [Int]
func nn av = solve 0 0 0
  where
    solve :: Int -> Int -> Int -> [Int]
    solve n px qx
      | n == 310000 = []
      | px == nn = ((px-qx):(solve (n+1) px px))
      | (av V.! px) /= n = ((px-qx):(solve (n+1) px px))
      | (av V.! qx) == n = solve n (px+1) qx

get1 :: [Int] -> Int
get1 x = (x!!0)

get2 :: [Int] -> Int
get2 x = (x!!1)

hantei :: (Int, Int) -> Bool
hantei x
  | fst(x) == 0 = True
  | otherwise = False

reflect :: [Int] -> Int -> [Int]
reflect x border = map hikizan x
  where
    hikizan :: Int -> Int
    hikizan t = t - border

tansaku :: Int -> V.Vector Int -> V.Vector Int -> V.Vector Int -> V.Vector Int -> Int
tansaku n xv yv ix iy = solve 0
  where
    solve :: Int -> Int
    solve pos
      | pos == n = 0
      | otherwise = newnum + (solve (pos+1))
        where newnum = if ((ix V.! (xv V.! pos)) == 1 && (iy V.! (yv V.! pos)) == 1) then 1 else 0

main = do
  -- 入力 --
  [h, w, n] <- (map read . words) <$> getLine
  s <- replicateM n getLine
  let s2 = map words s
  let a = map (map (read :: String -> Int)) s2
  
  -- パース --
  let x = map get1 a
  let y = map get2 a
  let xw = (V.fromList x) :: V.Vector Int
  let yw = (V.fromList y) :: V.Vector Int
  let xs = sort x
  let ys = sort y
  let xv = (V.fromList xs) :: V.Vector Int
  let yv = (V.fromList ys) :: V.Vector Int
  
  -- 本質部分 --
  let numx = func n xv
  let numy = func n yv
  let maxx = maximum numx
  let maxy = maximum numy
  let evalx = reflect numx maxx
  let evaly = reflect numy maxy
  let ex = zip evalx [0..310000]
  let ey = zip evaly [0..310000]
  let fx = filter hantei ex
  let fy = filter hantei ey
  let gx = snd (unzip fx)
  let gy = snd (unzip fy)
  let gx2 = (V.fromList gx) :: V.Vector Int
  let gy2 = (V.fromList gy) :: V.Vector Int
  
  -- 探索パート --
  let szx = length gx
  let szy = length gy
  let hx = func szx gx2
  let hy = func szy gy2
  let ix = (V.fromList hx) :: V.Vector Int
  let iy = (V.fromList hy) :: V.Vector Int
  let ret = tansaku n xw yw ix iy
  
  -- 答えを出力 --
  let ans = if (ret == (szx * szy)) then (maxx + maxy - 1) else (maxx + maxy)
  putStrLn $ show ans