#include <bits/extc++.h>

#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

using namespace std;
using ll = long long;
using pii = pair<int, int>;
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, N;
    cin>>n>>m>>N;
    vector<int> top(m, n), left(n, m);
    vector<vector<int>> blocks(n);
    for (int i=0; i<N; i++) {
        int x, y;
        cin>>x>>y;
        x--, y--;
        top[y]=min(top[y], x);
        left[x]=min(left[x], y);
        blocks[x].push_back(y);
    }
    ll ans=0;
    for (int i=0; i<left[0]; i++) {
        ans+=top[i];
    }

    ordered_set<int> st;
    for (int i=left[0]; i<m; i++) st.insert(i);
    for (int i=1; i<top[0]; i++) {
        if(!st.empty()) ans+=st.order_of_key(left[i]);
        for (auto x:blocks[i]) st.insert(x);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h> 
#define ll long long
#define forinc(i,a,b) for(int i=a;i<b;i++)
#define fordec(i,a,b) for(int i=a;i>b;i--)

using namespace std;
class Bit{
    public:
    vector<int> arr;
    int n;
    Bit(int n){
        arr = vector<int>(n+1,0);
        this->n=n;
    }
    void update(int index,int val){
        index+=1;
        for(int i=index;i<=n;i=i+(i&(-i))){
            
            arr[i]+=val;
        }
    }
    int get(int index){
        
        index+=1;
        int re = 0;
        for(int i=index;i>0;i=i-(i&(-i))){
            
            re+=arr[i];
        }
        return re;
    }
};

int main(){
    int H,M,W,x,y;
    ll re=0;
    
    cin>>H>>W>>M;
    vector<int> row(H,W),col(W,H);
    vector<vector<int>> ceil_block(H,vector<int>());
    Bit tree(W);
    forinc(i,0,M){
        
        cin>>x>>y;
        x--;y--;
        row[x]=min(row[x],y);
        col[y]=min(col[y],x);
        

    }
    // cout<<"here1";
    forinc(i,0,row[0]){
        
        re += (ll)col[i];
    } 
  	forinc(i,0,row[0]){
      if(col[i]<H)ceil_block[col[i]].push_back(i);
      }
    // cout<<"here";
    for(int i=0;i<col[0];i++){
       
        re+= (ll) tree.get(row[i]-1);
        re+= (ll)max(row[i]-row[0],0);
        for(auto j:ceil_block[i]){
            tree.update(j,1);
        }
       
    }
    cout<<re;
}