let input = require('fs').readFileSync('/dev/stdin', 'utf8')
// let input = require('fs').readFileSync('./sample_e.txt', 'utf8')
.split(/\n| /)
.map(item => parseInt(item))
.slice(0,-1)

const [height, width, ..._targets] = input
const targets = _targets.slice(1)
let bombMap = []

// Map作成
for(let i=0; i<height; i++){
    bombMap.push([])
    for(let j=0; j<width; j++){
        bombMap[i].push(false)
    }
}

let hlist = new Array(height).fill(0)
let wlist = new Array(width).fill(0)

const leng = targets.length / 2
for(let i=0; i<leng; i++){
    const [Y, X] = targets.slice(2*i, 2*i+2)
    hlist[Y-1] += 1
    wlist[X-1] += 1
    bombMap[Y-1][X-1] = true
}

const hmax = Math.max(...hlist)
const hindexes = []
for (let i=0; i<height; i++) {
    if(hlist[i] === hmax) hindexes.push(i)
}

const wmax = Math.max(...wlist)
const windexes = []
for (let i=0; i<width; i++) {
    if(wlist[i] === wmax) windexes.push(i)
}

let max
hindexes.forEach(hitem => {
    windexes.forEach(witem => {
        if(bombMap[hitem][witem]) return
        else max = hmax + wmax
    })
})

console.log(max || hmax + wmax - 1)
