/*
# Enjoy the journey #
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define forq(i , a , b) for (int i = (a); i <= (b); ++i)
#define qrof(i , b , a) for (int i = (a); i >= (b); --i)
#define forr(i , b) forq( i , 0 , b - 1 )
#define F first
#define S second
#define IF ->first
#define IS ->second
#define endl '\n'
#define qqmemset(array , val) memset (array , val , sizeof(array))
#define ALLV(vect) vect.begin() , vect.end()
#define mid (st + en) / 2
#define mid1 (2 * st + en) / 3
#define mid2 (2 * en + st) / 3
#define lef 2 * Node
#define rig lef + 1
mt19937 rng( chrono::steady_clock::now().time_since_epoch().count() );
#define Ran(a, b) rng() % ( (b) - (a) + 1 ) + (a)
ll R = 7 + 1e9 , R1 = 19491001 , R2 = 236 , NUMTESTCASE ;
const ll NN = 10 + 1e6 ;
const double pi = acos(-1.0) ;
int di [8] = {1 , 0 , -1 , 0 , 1 , -1 , 1 , -1 } , dj [8] = {0 , 1 , 0 , -1 , 1 , -1 , -1 , 1 } ;
int Deg [NN] , Dsu [NN] , Size [NN] , n , m , u , v , k ;
bool Find1 [NN] , Find2 [NN] ;
int Root (int u) {
return Dsu [u] == u ? u : Dsu [u] = Root (Dsu [u]) ;
}
void Merge (int u , int v) {
u = Root(u) ; v = Root(v) ;
if (u == v) return ;
if (u > v) swap(u , v) ;
Size [u] += Size [v] ;
Dsu [v] = u ;
}
int main()
{
cin >> n >> m >> k ;
forq (i , 1 , n + m)
Dsu [i] = i , Size [i] = 1 ;
forq (i , 1 , k) {
scanf("%d%d" , &u , &v) ;
Deg [u] ++ ;
v += n ;
Merge(u , v) ;
Find2 [v] = true ;
}
int M = 0 ;
forq (i , 1 , m) M += Find2 [i + n] ;
int Ans = INT_MAX ;
forq (i , 1 , n)
if (Deg [i]) {
int Temp = M - Deg [i] + 1 + Size [Root(i)] - 1 - Deg [i] ;
Ans = min(Ans , Temp) ;
}
cout << Ans ;
return 0;
}
Copy