// Arup Guha
// 11/7/2016
// Solution to 2016 SER D1 Problem E: Illumination

import java.util.*;
import java.io.*;

public class illumination {

	public static int n;
	public static int reach;
	public static int numLamps;
	public static int[][] lamps;

	public static void main(String[] args) throws Exception {

		// Get initial parameters.
		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		reach = stdin.nextInt();
		numLamps = stdin.nextInt();

		// Get lamp locations.
		lamps = new int[numLamps][2];
		for (int i=0; i<numLamps; i++)
			for (int j=0; j<2; j++)
				lamps[i][j] = stdin.nextInt();

		// Store two sat clauses here.
		ArrayList<int[]> list = new ArrayList<int[]>();
		for (int i=0; i<numLamps; i++) {
			for (int j=i+1; j<numLamps; j++) {

				// Both of these lamps (i,j) can not be set on the same row.
				if (lamps[i][0] == lamps[j][0] && Math.abs(lamps[i][1]-lamps[j][1]) <= 2*reach) {
					int[] tmp = new int[2];
					tmp[0] = 2*i;
					tmp[1] = 2*j;
					list.add(tmp);
				}

				// Both of these lamps can not be set on the same column.
				else if (lamps[i][1] == lamps[j][1] && Math.abs(lamps[i][0]-lamps[j][0]) <= 2*reach) {
					int[] tmp = new int[2];
					tmp[0] = 2*i+1;
					tmp[1] = 2*j+1;
					list.add(tmp);
				}
			}
		}

		// Copy into an array.
		int[][] clauses = new int[list.size()][];
		for (int i=0; i<list.size(); i++)
			clauses[i] = list.get(i);

		// Set up two sat object and solve it.
		twosat eqn = new twosat(clauses, numLamps);
		boolean res = eqn.isSatisfiable();

		// Print the desired result.
		if (res)
			System.out.println(1);
		else
			System.out.println(0);

	}
}

class twosat {

	private int numVars;
	private int numClauses;
	private int[][] clauses;
	private Boolean[] vars;
	private ArrayList[] forcedVars;

	public twosat(int[][] myClauses, int myVars) {

		numVars = myVars;
		clauses = myClauses;
		numClauses = clauses.length;
		forcedVars = new ArrayList[2*numVars];
		for (int i=0; i<forcedVars.length; i++)
			forcedVars[i] = new ArrayList<Integer>();
		vars = new Boolean[numVars];
		Arrays.fill(vars, null);

		// Read through each clause.
		for (int i=0; i<clauses.length; i++) {

			// Read in this clause.
			int v1 = clauses[i][0];
			int v2 = clauses[i][1];

			// Add which variables are forced, if the current item is false.
			forcedVars[v1].add(v2);
			forcedVars[v2].add(v1);
		}
	}

	public boolean isSatisfiable() {

		// Go through each variable, trying to set it.
		for (int i=0; i<vars.length; i++) {

			// We've already set this variable - see if it's viable.
			if (vars[i] != null) {
				if (!consistent(i)) return false;
				continue;
			}

			// Try true.
			vars[i] = true;
			boolean works = isSatRec(i);

			// Well if that didn't work, this must be false, if it is to work at all.
			if (!works) {
				vars[i] = false;
				if (!consistent(i)) return false;
			}
		}

		// If we make it here, it must be satisfiable.
		return true;
	}

	private boolean consistent(int ID) {

		int index = 0;

		// Set list of forced variables.
		if (vars[ID]) index = 2*ID+1;
		else		  index = 2*ID;

		// All clauses linked to the false version of this variable must be true.
		ArrayList<Integer> forced = forcedVars[index];
		for (int i=0; i<forced.size(); i++) {
			int item = forced.get(i);
			if (item%2 == 0 && vars[item/2] != null && !vars[item/2]) return false;
			if (item%2 == 1 && vars[item/2] != null && vars[item/2]) return false;
		}

		// If we get here, we are okay.
		return true;
	}

	// Recursively try to set forced variables according to the current setting of variable i.
	private boolean isSatRec(int ID) {

		// Not sure if I need to do this; just being cautious.
		if (!consistent(ID)) {
			vars[ID] = null;
			return false;
		}

		// Get forced list.
		int index = 0;
		if (vars[ID]) index = 2*ID+1;
		else	 	  index = 2*ID;

		// All clauses linked to the false version of this variable must be true.
		ArrayList<Integer> forced = forcedVars[index];
		for (int i=0; i<forced.size(); i++) {
			int item = forced.get(i);
			if ((item%2 == 0 && vars[item/2] != null && !vars[item/2]) || (item%2 == 1 && vars[item/2] != null && vars[item/2])) {
				vars[ID] = null;
				return false;
			}

			// Don't want to relitigate this case.
			if (vars[item/2] != null) continue;

			// No problem, so just set this variable.
			vars[item/2] = item%2 == 0 ? true : false;

			// Recursively solve here.
			boolean res = isSatRec(item/2);
			if (!res) {
				vars[ID] = null;
				return false;
			}
		}

		// If we get here, we're good.
		return true;
	}
}