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WhoOyAtLXd3OwogICAgaW4uZW1wbGFjZV9iYWNrKGhoLCB3dyk7CiAgICArK2NudF9yb3dbaGhdOyArK2NudF9jb2xbd3ddOwogIH0KCiAgaW50IG14X3JvdyA9ICptYXhfZWxlbWVudChhbGwoY250X3JvdykpOwogIGludCBteF9jb2wgPSAqbWF4X2VsZW1lbnQoYWxsKGNudF9jb2wpKTsKICBpbnQgYW5zID0gbXhfcm93ICsgbXhfY29sOwogIGludDY0IGNhbiA9IGNvdW50KGFsbChjbnRfcm93KSwgbXhfcm93KSAqIGNvdW50KGFsbChjbnRfY29sKSwgbXhfY29sKTsKICBpZiAoY2FuID4gbSkgewogICAgY291dCA8PCBhbnMgPDwgZW5kbDsKICB9IGVsc2UgewogICAgaW50IGJhZCA9IDA7CiAgICBmb3IgKGF1dG8gZSA6IGluKSBiYWQgKz0gKGNudF9yb3dbZS5maXJzdF0gKyBjbnRfY29sW2Uuc2Vjb25kXSA9PSBhbnMpOwogICAgaWYgKGNhbiA+IGJhZCkgewogICAgICBjb3V0IDw8IGFucyA8PCBlbmRsOwogICAgfSBlbHNlIHsKICAgICAgY291dCA8PCBhbnMgLSAxIDw8IGVuZGw7CiAgICB9CiAgfQoKICByZXR1cm4gMDsKfQoiIiIKCndpdGggb3Blbignc29sLmNwcCcsICd3JykgYXMgZjoKICAgIGYud3JpdGUoY29kZSkKCnN1YnByb2Nlc3MuUG9wZW4oWydnKysnLCAnLXN0ZD1jKysxNycsICctTzInLCAnc29sLmNwcCddKS5jb21tdW5pY2F0ZSgpCnN1YnByb2Nlc3MuUG9wZW4oWycuL2Eub3V0J10sIHN0ZGluPXN5cy5zdGRpbiwgc3Rkb3V0PXN5cy5zdGRvdXQpLmNvbW11bmljYXRlKCk='))

# Optimized solution
# This code is generated by [Atcoder_base64](https://github.com/kyomukyomupurin/AtCoder_base64)
# Original source code : 

"""
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int h, w, m; cin >> h >> w >> m;
  vector<pair<int, int>> in;

  vector<int> cnt_row(h, 0), cnt_col(w, 0);

  for (int i = 0; i < m; ++i) {
    int hh, ww; cin >> hh >> ww;
    --hh; --ww;
    in.emplace_back(hh, ww);
    ++cnt_row[hh]; ++cnt_col[ww];
  }

  int mx_row = *max_element(all(cnt_row));
  int mx_col = *max_element(all(cnt_col));
  int ans = mx_row + mx_col;
  int64 can = count(all(cnt_row), mx_row) * count(all(cnt_col), mx_col);
  if (can > m) {
    cout << ans << endl;
  } else {
    int bad = 0;
    for (auto e : in) bad += (cnt_row[e.first] + cnt_col[e.second] == ans);
    if (can > bad) {
      cout << ans << endl;
    } else {
      cout << ans - 1 << endl;
    }
  }

  return 0;
}

"""

import base64
import subprocess
import zlib


exe_bin = "c%1E9eQ+Dcb>9O(5t1kX`mjt%mI*tQL&XwINR&jxkwuUMd5DiP!w*|+EuBCB6k&q^0~{n$Bd1JBy1CGB7>|>vjWSi;W~N``DCsnHKRh8#SszW>krOp`B|Fxnk^_XMEk}te*%r~ad%M8h@y<>&{gcZ9-o4+x_xA1Ey}jGT;~xfu77NEAR;=g&gt-$Ag>RsE-{ztSVD)G*eBX)IqeZ~mRC0QHgVR!bu^mOP-lFh&dI!={PDRU*d3kq*mLlXX>S15&*VA^^yEXI@ZI>_8>RG5>JJoBa@{GEu9;2*(Hu~wJxSlp6EwxeFenpDl>+>#!*HZy$DbxEL=q*COeWB)12W`(RE@!B}jIwdKFCOdJUUy$SvN;}0WCk}6)^Fduz0Q+PdbSXsTvWDocQ=v8<84v-yozGDzIE{f7cLG(clEz6)Of!6+$)dFe(eD)yAqYg4M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