open System.Linq

let h, w, m =
    stdin.ReadLine().Split()
    |> Array.map int
    |> fun ary -> ary.[0], ary.[1], ary.[2]

let targets =
    [| for _ in 1 .. m do
        stdin.ReadLine().Split()
        |> Array.map int
        |> fun ary -> [| ary.[0]; ary.[1] |] |]

let RowsWithMostTargs =
    let counts =
        targets |> Array.countBy (fun targ -> targ.[0])

    let max =
        counts
        |> Array.maxBy (fun (key, n) -> n)
        |> fun (key, n) -> n

    counts
    |> Array.filter (fun (key, n) -> n = max)
    |> Array.map (fun (key, n) -> key)

let ColsWithMostTargs =
    let counts =
        targets |> Array.countBy (fun targ -> targ.[1])

    let max =
        counts
        |> Array.maxBy (fun (key, n) -> n)
        |> fun (key, n) -> n

    counts
    |> Array.filter (fun (key, n) -> n = max)
    |> Array.map (fun (key, n) -> key)

let maxRowsxCols =
    [| for r in RowsWithMostTargs do
        for c in ColsWithMostTargs -> [| r; c |] |]

let selectedPoint =
    match maxRowsxCols |> Array.except targets with
    | [||] -> maxRowsxCols.[0]
    | ary -> ary.[0]

targets.Count(fun targ ->
    targ.[0] = selectedPoint.[0]
    || targ.[1] = selectedPoint.[1])
|> printfn "%d"
