#include "bits/stdc++.h"
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<pair<int, int>> edges;
for (int i = 0; i < k; ++i) {
int a, b;
cin >> a >> b;
--a, --b;
edges.emplace_back(a, b);
}
vector<int> degree(n);
for (auto [a, b] : edges) {
degree[a] += 1;
}
int ans = 0;
for (int i = 0; i < n; ++i) {
if (degree[i]) ans += 1;
}
vector<vector<int>> gr(m);
for (auto [a, b] : edges) {
gr[b].push_back(a);
}
for (int i = 0; i < m; ++i) {
int new_ans = ans + 1;
for (int v : gr[i]) {
if (degree[v] == 1) {
new_ans -= 1;
}
}
ans = min(ans, new_ans);
}
cout << ans << '\n';
return 0;
}
Copy