#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 200005
vector<int>tree[4*N];
void build_tree( int cur , int l , int r, int a[])
{
     if( l==r )
     {
            tree[cur].push_back(a[l]);
            return ;
     }
     int mid = l+(r-l)/2;
     build_tree(2*cur+1 , l , mid, a); // Build left tree 
     build_tree(2*cur+2 , mid+1 , r, a); // Build right tree
     vector<int> arr(tree[2*cur+1].size() + tree[2*cur+2].size());
     merge(tree[2*cur+1].begin(), tree[2*cur+1].end(), tree[2*cur+2].begin(), tree[2*cur+2].end(), arr.begin());
     tree[cur] = arr; //Merging the two sorted arrays
}
int query(int cur,int l, int r, int x, int y, int k)
{
      if( r < x || l > y )
      {
            return 0; //out of range
      }
      if( x<=l && r<=y )
      {
              //Binary search over the current sorted vector to find elements smaller than K

              return lower_bound(tree[cur].begin(),tree[cur].end(),k)-tree[cur].begin();
      }
      int mid=l+(r-l)/2;
     return query(2*cur+1,l,mid,x,y,k)+query(2*cur+2,mid+1,r,x,y,k);
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h, w, m;
    cin >> h >> w >> m;
    vector<int> row[h+1], col[w+1];
    int i, mr = w+1, mc = h+1;
    for(i=1;i<=m;i++)
    {
        int x, y;
        cin >> x >> y;
        row[x].push_back(y);
        col[y].push_back(x);
        if(x == 1)
            mr = min(mr, y);
        if(y == 1)
            mc = min(mc, x);
    }
    for(i=1;i<=h;i++)
        sort(row[i].begin(), row[i].end());
    for(i=1;i<=w;i++)
        sort(col[i].begin(), col[i].end());
   // cout << "hello" << endl;
    int ans = 0;
    vector<pair<int, int>> vec;
    int arr[h+1];
    for(i=0;i<mc;i++)
        arr[i] = w+1;
    for(i=mc;i<=h;i++)
        arr[i] = 0;
    for(i=1;i<mc;i++)
    {
        if(row[i].size() == 0)
            ans+=w, arr[i] = w+1;
        else
            ans+=(row[i][0] - 1), arr[i] = row[i][0];
    }
 //   cout << ans << " " << "hello" << " " << mc << " " << mr << endl; 
    build_tree(0, 0, h, arr);
   // cout << "hello" << endl;
    for(i=2;i<mr;i++)
    {
        int up;
        if(col[i].size() == 0)
            up = h;
        else
            up = col[i][0] - 1;
        // how many numbers in range [1, up] are less than 'i' that is count of 'k' such that arr[k] < i, 1 <= k <= up
        ans+=query(0, 0, h, 1, up, i);
    }
    cout << ans << '\n';
}
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

#include <bits/stdc++.h>
using namespace std;

char readchar() {
  static char buf[1 << 15], *ptr = buf, *end = buf;
  if (ptr == end) ptr = buf, end = buf + fread(buf, 1, 1 << 15, stdin);
  return *ptr++;
}
void writechar(char c = 0) {
  static char buf[1 << 15], *ptr = buf;
  if (ptr == end(buf) or c == 0) fwrite(buf, 1, ptr - buf, stdout), ptr = buf;
  *ptr++ = c;
}
template <class Z = int> Z getint() {
  char c = readchar();
  bool neg = c == '-';
  Z res = neg ? 0 : c - '0';
  while (isdigit(c = readchar())) res = res * 10 + (c - '0');
  return neg ? -res : res;
}
template <class Z> void putint(Z a, char delim = '\n') {
  if (a < 0) writechar('-'), a = -a;
  int d[40], i = 0;
  do d[i++] = a % 10; while (a /= 10);
  while (i--) writechar('0' + d[i]);
  writechar(delim);
}
string getstring(char delim = '\n') {
  string res;
  for (char c; (c = readchar()) != delim; ) res += c;
  return res;
}
void putstring(string s, char delim = '\n') {
  for (char c : s) writechar(c);
  writechar(delim);
}

struct bipartite_matching {
  vector<vector<int>> g;
  vector<int> r, c, vis;
  bipartite_matching(int h = 0, int w = 0) : g(h), r(h, -1), c(w, -1), vis(h) {}
  void add(int i, int j) { g[i].push_back(j); }
  bool dfs(int i) {
    if (exchange(vis[i], true)) return false;
    for (int j : g[i]) if (c[j] == -1) return r[i] = j, c[j] = i, true;
    for (int j : g[i]) if (dfs(c[j])) return r[i] = j, c[j] = i, true;
    return false;
  }
  int run() {
    while (true) {
      fill(begin(vis), end(vis), false);
      bool updated = false;
      for (int i = 0; i < (int)r.size(); ++i) if (r[i] == -1) updated |= dfs(i);
      if (not updated) break;
    }
    return r.size() - count(begin(r), end(r), -1);
  }
};


signed main(){
  int n;cin>>n;
  bipartite_matching g(n,400000);
  REP(i,n){
    int a,b;cin>>a>>b;a--;b--;
    g.add(i,a);
    g.add(i,b);
  }
  cout<<g.run()<<endl;
  //putint(g.run());
}
