void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.typecons;

  int w, h, n; rd(w, h, n);
  alias P=Tuple!(int, "x", int, "y");
  auto a=new P[](0);
  foreach(_; 0..n){
    int x, y; rd(x, y);
    a~=P(x, y);
  }

  auto b=a.dup;
  sort(a); reverse(a);
  sort!"a[1]==b[1] ? a[0]>b[0] : a[1]>b[1]"(b);
  int[P] used;
  
  int i=0, j=0, sum=0;
  while(1){
    auto p=a[i], q=b[j];
    sum+=min(p.y, q.x);
    if(p==q) break;

    while(i<n && a[i].y==p.y) used[a[i++]]=1;
    while(j<n && b[j].x==q.x) used[b[j++]]=1;

    if(used.length>=n) break;
  }

  writeln(sum);
  
  
}

void chmax(T)(ref T x, T y){
  if(x<y) x=y;
}
void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}