2 5 10
2 2
1 1
1 4
2 1
1 2
1 5
2 4
2 5
1 3
2 3
 2 2 2
1 1
2 2
 3 3 9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
 7 5 35
5 3
3 5
1 1
2 5
6 4
7 2
5 1
3 4
6 5
7 3
4 1
2 2
4 2
2 4
4 3
3 3
6 1
1 2
4 5
1 3
2 1
5 5
7 5
7 1
6 2
1 4
1 5
3 2
4 4
5 2
2 3
6 3
7 4
5 4
3 1
 1 5 4
1 1
1 2
1 4
1 5
 1 1 1
1 1
 5 7 21
4 4
4 5
5 5
5 6
5 7
5 1
5 2
4 2
3 2
3 1
3 7
3 6
2 6
1 6
1 7
1 1
1 2
1 3
1 4
2 4
3 4
 2 1 1
1 1
 2 2 4
2 1
1 1
1 2
2 2
 3000 3000 1
2222 738
 5 7 35
1 2
2 3
5 1
5 7
4 4
5 3
3 1
2 6
4 5
2 7
4 1
2 1
2 2
1 7
5 6
3 6
4 6
1 6
1 1
3 3
3 4
4 2
2 5
5 5
3 5
2 4
1 5
1 3
4 3
5 4
1 4
3 7
4 7
3 2
5 2
 5 4 1
4 1
 3 4 12
2 3
3 2
2 2
2 1
1 2
3 1
1 4
1 3
3 3
2 4
3 4
1 1
 3 3 3
1 1
2 2
3 3

8
 1
 6
 26
 4
 0
 20
 0
 2
 1
 28
 1
 9
 3

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.TreeSet;

public class Main {

	static boolean [][] occ ;

	public class Point implements Comparable<Point>{
		int x ;
		int y;
		Point prev;
		public Point(int xx , int yy) {
			x = xx;
			y = yy;
		}
		public int compareTo(Point p) {
			int comp = new Integer(x).compareTo(p.x);
			if(comp!=0) {
				return comp;
			}
			return  new Integer(y).compareTo(p.y);
		}
	}

	static Main main;

	static ArrayList<Point> start;

	static int r;

	static int c;

	public static void main(String [] args ) {
		main = new Main();
		try{
			String str;			
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			BufferedOutputStream bos = new BufferedOutputStream(System.out);
			String eol = System.getProperty("line.separator");
			byte [] eolb = eol.getBytes();
			byte[] spaceb= " ".getBytes();


			str  = br.readLine();
			int blank = str.indexOf( " ");
			r = Integer.parseInt(str.substring(0,blank));
			str = str.substring(blank+1);
			blank = str.indexOf( " ");
			c = Integer.parseInt(str.substring(0,blank));
			int n = Integer.parseInt(str.substring(blank+1));
			occ = new boolean[r][c];
			start = new ArrayList<Point>();
			for(int j = 0 ; j < c ; j++) {
				start.add(main.new Point(0,j));
			}
			for(int i = 0 ; i < r ; i++) {
				for(int j = 0 ; j < c ; j++) {
					occ[i][j] = false;
				}
			}
			int land = 0;
			TreeSet<Point> path = findPath();
			for(int i = 0 ; i < n ; i++) {
				str  = br.readLine();
				blank = str.indexOf( " ");
				int row = Integer.parseInt(str.substring(0,blank)) - 1;
				int col = Integer.parseInt(str.substring(blank+1)) - 1;
				Point p = main.new Point(row,col);
				if(!path.contains(p)) {
					occ[row][col] = true;
					land++;
				} else {
					occ[row][col] = true;
					TreeSet<Point> newPath = findPath();
					if(newPath!=null) {
						occ[row][col] = true;
						land++;
						path = newPath;
					} else {
						occ[row][col] = false;
					}
				}
			}
			bos.write(new Integer(land).toString().getBytes());
			bos.write(eolb);
			bos.flush();
		}  catch(IOException ioe) {
			ioe.printStackTrace();
		}
	}

	public static TreeSet<Point> findPath() {
		for(int i = start.size()-1;i>=0;i--) {
			if(!occ[start.get(i).x][start.get(i).y]) {
				visited = new ArrayList<Point>();
				Point last = dfs(start.get(i));
				for(int p = 0 ; p < visited.size() ; p++) {
					occ[visited.get(p).x][visited.get(p).y]= false; 
				}
				if(last==null) {
					//start.remove(start.size()-1);
				} else if(last.x!=(r-1)) {
					//start.remove(start.size()-1);
				} else {
					TreeSet<Point> path = new TreeSet<Point>();
					while(last!=null) {
						path.add(last);
						last = last.prev;
					}
					return path;
				}
			} else {
				start.remove(start.size()-1);
			}
		}
		return null;
	}

	static ArrayList<Point> visited;
	
	public static Point dfs(Point p) {
		if(p.x==(r-1)) {
			return p;
		}
		ArrayList<Point> neigh = getNeighbors(p);
		occ[p.x][p.y]= true; 
		visited.add(p);
		for(int i = 0 ; i < neigh.size() ; i++) {
			neigh.get(i).prev = p; 
			Point ret = dfs(neigh.get(i));
			if(ret!=null) {
				occ[p.x][p.y]=false;
				return ret;
			}
		}
		occ[p.x][p.y]=false; 
		return null;
	}

	public static ArrayList<Point> getNeighbors(Point p) {
		ArrayList<Point> neigh = new ArrayList<Point>();
		if(p.x>0) {
			if(!occ[p.x-1][p.y]){ 
				neigh.add(main.new Point(p.x-1,p.y));
			}
		} 
		if(p.y>0) {
			if(!occ[p.x][p.y-1]) {
				neigh.add(main.new Point(p.x,p.y-1));
			}
		} else {
			if(!occ[p.x][c-1]) {
				neigh.add(main.new Point(p.x,c-1));
			}
		}
		if(p.x<(r-1)) {
			if(!occ[p.x+1][p.y]){ 
				neigh.add(main.new Point(p.x+1,p.y));
			}
		}
		if(p.y<(c-1)) {
			if(!occ[p.x][p.y+1]) {
				neigh.add(main.new Point(p.x,p.y+1));
			}
		} else {
			if(!occ[p.x][0]) {
				neigh.add(main.new Point(p.x,0));
			}
		}
		return neigh;
	}
}
