#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAX = 300005;

int R[MAX];
void reset()
{
	for(int i = 0; i < MAX; i++) R[i] = i;
}
int find(int v)
{
	if(R[v] != v) R[v] = find(R[v]);
	return R[v];
}
void uni(int u, int v)
{
	R[find(u)] = find(v);
}

int N, M, Q;
vector<int> G[MAX];
bool visited[MAX];

int maxdepth = -1;
int maxv = 0;
void dfs(int u, int p, int d)
{
	visited[u] = true;
	if(d > maxdepth)
	{
		maxdepth = d;
		maxv = u;
	}
	//dfsstack.push_back(u);
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		dfs(v, u, d + 1);
	}
	//dfsstack.pop_back();
}

//vector<int> dfsstack;
/*bool dfs2(int u, int p, int d)
{
	dfsstack.push_back(u);
	if(d == maxdepth) return true;
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		if(dfs(v, u, d + 1)) return true;
	}
	dfsstack.pop_back();
}*/

int diam[MAX];

int main()
{
	cin >> N >> M >> Q;
	reset();
	for(int i = 0; i < M; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
		uni(a, b);
	}
	memset(visited, 0, sizeof(visited));
	for(int u = 1; u <= N; u++)
	{
		if(visited[u]) continue;
		//dfsstack.clear();
		maxdepth = -1;
		dfs(u, -1, 0);
		maxdepth = -1;
		dfs(maxv, -1, 0);
		diam[find(u)] = maxdepth;
		//dfs2(maxv, -1, 0);
	}
	for(int q = 0; q < Q; q++)
	{
		int t;
		scanf("%d", &t);
		if(t == 1)
		{
			int u;
			scanf("%d", &u);
			printf("%d\n", diam[find(u)]);
		}
		else
		{
			int u, v;
			scanf("%d %d", &u, &v);
			if(find(u) == find(v)) continue;
			int d1 = diam[find(u)], d2 = diam[find(v)];
			uni(u, v);
			diam[find(u)] = max(max(d1, d2), (d1 + 1) / 2 + (d2 + 1) / 2 + 1);
		}
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAX = 300005;

int R[MAX];
void reset()
{
	for(int i = 0; i < MAX; i++) R[i] = -1;
}
int find(int v)
{
	if(R[v] < 0) return v;
	return find(R[v]);
}
void uni(int u, int v)
{
	//cout << "unioning " << u << ' ' << v<< endl;
	int ru = find(u), rv = find(v);
	if(-R[ru] <= -R[rv])
	{
		R[rv] += R[ru];
		R[ru] = rv;
	}
	else if(-R[ru] > -R[rv])
	{
		R[ru] += R[rv];
		R[rv] = ru;
	}
}

int N, M, Q;
vector<int> G[MAX];
bool visited[MAX];

int depth[MAX];
int maxdepth(int u, int p)
{
	visited[u] = true;
	int best = 0;
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		best = max(best, maxdepth(v, u) + 1);
	}
	depth[u] = best;
	return best;
}

int get_diam(int u, int p)
{
	int best = 0;
	vector<int> depths;
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		depths.push_back(depth[v]);
		best = max(best, get_diam(v, u));
	}
	if(depths.size() == 1) best = max(best, 1 + depths[0]);
	if(depths.size() >= 2)
	{
		sort(depths.begin(), depths.end());
		best = max(best, 2 + depths[depths.size() - 2] + depths.back());
	}
	return best;
}

int diam[MAX];

int main()
{
	cin >> N >> M >> Q;
	reset();
	for(int i = 0; i < M; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
		uni(a, b);
	}
	memset(visited, 0, sizeof(visited));
	for(int u = 1; u <= N; u++)
	{
		if(visited[u]) continue;
		maxdepth(u, -1);
		diam[find(u)] = get_diam(u, -1);
		//dfsstack.clear();
		//maxdepth = -1;
		//dfs(u, -1, 0);
		//maxdepth = -1;
		//dfs(maxv, -1, 0);
		//diam[find(u)] = maxdepth;
		//dfs2(maxv, -1, 0);
	}
	for(int q = 0; q < Q; q++)
	{
		int t;
		scanf("%d", &t);
		if(t == 1)
		{
			int u;
			scanf("%d", &u);
			printf("%d\n", diam[find(u)]);
		}
		else
		{
			int u, v;
			scanf("%d %d", &u, &v);
			if(find(u) == find(v)) continue;
			int d1 = diam[find(u)], d2 = diam[find(v)];
			uni(u, v);
			diam[find(u)] = (d1 + 1) / 2 + (d2 + 1) / 2 + 1;
		}
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAX = 300005;

int R[MAX];
void reset()
{
	for(int i = 0; i < MAX; i++) R[i] = i;
}
int find(int v)
{
	if(R[v] != v) R[v] = find(R[v]);
	return R[v];
}
void uni(int u, int v)
{
	R[find(u)] = find(v);
}

int N, M, Q;
vector<int> G[MAX];
bool visited[MAX];

int maxdepth = -1;
int maxv = 0;
void dfs(int u, int p, int d)
{
	visited[u] = true;
	if(d > maxdepth)
	{
		maxdepth = d;
		maxv = u;
	}
	//dfsstack.push_back(u);
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		dfs(v, u, d + 1);
	}
	//dfsstack.pop_back();
}

//vector<int> dfsstack;
/*bool dfs2(int u, int p, int d)
{
	dfsstack.push_back(u);
	if(d == maxdepth) return true;
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		if(dfs(v, u, d + 1)) return true;
	}
	dfsstack.pop_back();
}*/

int diam[MAX];

int main()
{
	cin >> N >> M >> Q;
	reset();
	for(int i = 0; i < M; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
		uni(a, b);
	}
	memset(visited, 0, sizeof(visited));
	for(int u = 1; u <= N; u++)
	{
		if(visited[u]) continue;
		//dfsstack.clear();
		maxdepth = -1;
		dfs(u, -1, 0);
		maxdepth = -1;
		dfs(maxv, -1, 0);
		diam[find(u)] = maxdepth;
		//dfs2(maxv, -1, 0);
	}
	for(int q = 0; q < Q; q++)
	{
		int t;
		scanf("%d", &t);
		if(t == 1)
		{
			int u;
			scanf("%d", &u);
			printf("%d ", diam[find(u)]);
		}
		else
		{
			int u, v;
			scanf("%d %d", &u, &v);
			if(find(u) == find(v)) continue;
			int d1 = diam[find(u)], d2 = diam[find(v)];
			uni(u, v);
			diam[find(u)] = max((max(d1,d2),(d1 + 1) / 2 + (d2 + 1) / 2 + 1);
		}
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAX = 300005;

int R[MAX];
void reset()
{
	for(int i = 0; i < MAX; i++) R[i] = -1;
}
int find(int v)
{
	if(R[v] < 0) return v;
	return find(R[v]);
}
void uni(int u, int v)
{
	//cout << "unioning " << u << ' ' << v<< endl;
	int ru = find(u), rv = find(v);
	if(-R[ru] <= -R[rv])
	{
		R[rv] += R[ru];
		R[ru] = rv;
	}
	else if(-R[ru] > -R[rv])
	{
		R[ru] += R[rv];
		R[rv] = ru;
	}
}

int N, M, Q;
vector<int> G[MAX];
bool visited[MAX];

int maxdepth = -1;
int maxv = 0;
void dfs(int u, int p, int d)
{
	visited[u] = true;
	if(d > maxdepth)
	{
		maxdepth = d;
		maxv = u;
	}
	//dfsstack.push_back(u);
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		dfs(v, u, d + 1);
	}
	//dfsstack.pop_back();
}

//vector<int> dfsstack;
/*bool dfs2(int u, int p, int d)
{
	dfsstack.push_back(u);
	if(d == maxdepth) return true;
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		if(dfs(v, u, d + 1)) return true;
	}
	dfsstack.pop_back();
}*/

int diam[MAX];

int main()
{
	cin >> N >> M >> Q;
	reset();
	for(int i = 0; i < M; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
		uni(a, b);
	}
	memset(visited, 0, sizeof(visited));
	for(int u = 1; u <= N; u++)
	{
		if(visited[u]) continue;
		//dfsstack.clear();
		maxdepth = -1;
		dfs(u, -1, 0);
		maxdepth = -1;
		dfs(maxv, -1, 0);
		diam[find(u)] = maxdepth;
		//dfs2(maxv, -1, 0);
	}
	for(int q = 0; q < Q; q++)
	{
		int t;
		scanf("%d", &t);
		if(t == 1)
		{
			int u;
			scanf("%d", &u);
			printf("%d\n", diam[find(u)]);
		}
		else
		{
			int u, v;
			scanf("%d %d", &u, &v);
			if(find(u) == find(v)) continue;
			int d1 = diam[find(u)], d2 = diam[find(v)];
			uni(u, v);
			diam[find(u)] = (d1 + 1) / 2 + (d2 + 1) / 2 + 1;
		}
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAX = 300005;

int R[MAX];
void reset()
{
	for(int i = 0; i < MAX; i++) R[i] = i;
}
int find(int v)
{
	if(R[v] != v) R[v] = find(R[v]);
	return R[v];
}
void uni(int u, int v)
{
	R[find(u)] = find(v);
}

int N, M, Q;
vector<int> G[MAX];
bool visited[MAX];

int maxdepth = -1;
int maxv = 0;
void dfs(int u, int p, int d)
{
	visited[u] = true;
	if(d > maxdepth)
	{
		maxdepth = d;
		maxv = u;
	}
	//dfsstack.push_back(u);
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		dfs(v, u, d + 1);
	}
	//dfsstack.pop_back();
}

//vector<int> dfsstack;
/*bool dfs2(int u, int p, int d)
{
	dfsstack.push_back(u);
	if(d == maxdepth) return true;
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		if(dfs(v, u, d + 1)) return true;
	}
	dfsstack.pop_back();
}*/

int diam[MAX];

int main()
{
	cin >> N >> M >> Q;
	reset();
	for(int i = 0; i < M; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
		uni(a, b);
	}
	memset(visited, 0, sizeof(visited));
	for(int u = 1; u <= N; u++)
	{
		if(visited[u]) continue;
		//dfsstack.clear();
		maxdepth = -1;
		dfs(u, -1, 0);
		maxdepth = -1;
		dfs(maxv, -1, 0);
		diam[find(u)] = maxdepth;
		//dfs2(maxv, -1, 0);
	}
	for(int q = 0; q < Q; q++)
	{
		int t;
		scanf("%d", &t);
		if(t == 1)
		{
			int u;
			scanf("%d", &u);
			printf("%d ", diam[find(u)]);
		}
		else
		{
			int u, v;
			scanf("%d %d", &u, &v);
			if(find(u) == find(v)) continue;
			int d1 = diam[find(u)], d2 = diam[find(v)];
			uni(u, v);
			diam[find(u)] = (d1 + 1) / 2 + (d2 + 1) / 2 + 1;
		}
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAX = 300005;

int R[MAX];
void reset()
{
	for(int i = 0; i < MAX; i++) R[i] = -1;
}
int find(int v)
{
	if(R[v] < 0) return v;
	return find(R[v]);
}
void uni(int u, int v)
{
	//cout << "unioning " << u << ' ' << v<< endl;
	int ru = find(u), rv = find(v);
	if(-R[ru] <= -R[rv])
	{
		R[rv] += R[ru];
		R[ru] = rv;
	}
	else if(-R[ru] > -R[rv])
	{
		R[ru] += R[rv];
		R[rv] = ru;
	}
}

int N, M, Q;
vector<int> G[MAX];
bool visited[MAX];

int depth[MAX];
int maxdepth(int u, int p)
{
	visited[u] = true;
	int best = 0;
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		best = max(best, maxdepth(v, u) + 1);
	}
	depth[u] = best;
	return best;
}

int get_diam(int u, int p)
{
	int best = 0;
	vector<int> depths;
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		depths.push_back(depth[v]);
		best = max(best, get_diam(v, u));
	}
	if(depths.size() == 1) best = max(best, 1 + depths[0]);
	if(depths.size() >= 2)
	{
		sort(depths.begin(), depths.end());
		best = max(best, 2 + depths[depths.size() - 2] + depths.back());
	}
	return best;
}

int diam[MAX];

int main()
{
	cin >> N >> M >> Q;
	reset();
	for(int i = 0; i < M; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
		uni(a, b);
	}
	memset(visited, 0, sizeof(visited));
	for(int u = 1; u <= N; u++)
	{
		if(visited[u]) continue;
		diam[find(u)] = get_diam(u, -1);
		//dfsstack.clear();
		//maxdepth = -1;
		//dfs(u, -1, 0);
		//maxdepth = -1;
		//dfs(maxv, -1, 0);
		//diam[find(u)] = maxdepth;
		//dfs2(maxv, -1, 0);
	}
	for(int q = 0; q < Q; q++)
	{
		int t;
		scanf("%d", &t);
		if(t == 1)
		{
			int u;
			scanf("%d", &u);
			printf("%d\n", diam[find(u)]);
		}
		else
		{
			int u, v;
			scanf("%d %d", &u, &v);
			if(find(u) == find(v)) continue;
			int d1 = diam[find(u)], d2 = diam[find(v)];
			uni(u, v);
			diam[find(u)] = (d1 + 1) / 2 + (d2 + 1) / 2 + 1;
		}
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAX = 300005;

int R[MAX];
void reset()
{
	for(int i = 0; i < MAX; i++) R[i] = i;
}
int find(int v)
{
	if(R[v] != v) R[v] = find(R[v]);
	return R[v];
}
void uni(int u, int v)
{
	R[find(u)] = find(v);
}

int N, M, Q;
vector<int> G[MAX];
bool visited[MAX];

int maxdepth = -1;
int maxv = 0;
void dfs(int u, int p, int d)
{
	visited[u] = true;
	if(d > maxdepth)
	{
		maxdepth = d;
		maxv = u;
	}
	//dfsstack.push_back(u);
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		dfs(v, u, d + 1);
	}
	//dfsstack.pop_back();
}

//vector<int> dfsstack;
/*bool dfs2(int u, int p, int d)
{
	dfsstack.push_back(u);
	if(d == maxdepth) return true;
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		if(dfs(v, u, d + 1)) return true;
	}
	dfsstack.pop_back();
}*/

int diam[MAX];

int main()
{
	cin >> N >> M >> Q;
	reset();
	for(int i = 0; i < M; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
		uni(a, b);
	}
	memset(visited, 0, sizeof(visited));
	for(int u = 1; u <= N; u++)
	{
		if(visited[u]) continue;
		//dfsstack.clear();
		maxdepth = -1;
		dfs(u, -1, 0);
		maxdepth = -1;
		dfs(maxv, -1, 0);
		diam[find(u)] = maxdepth;
		//dfs2(maxv, -1, 0);
	}
	for(int q = 0; q < Q; q++)
	{
		int t;
		scanf("%d", &t);
		if(t == 1)
		{
			int u;
			scanf("%d", &u);
			printf("%d\n", diam[find(u)]);
		}
		else
		{
			int u, v;
			scanf("%d %d", &u, &v);
			int d1 = diam[find(u)], d2 = diam[find(v)];
			uni(u, v);
			diam[find(u)] = max(max(d1,d2),(d1 + 1) / 2 + (d2 + 1) / 2 + 1);
		}
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAX = 300005;

int R[MAX];
void reset()
{
	for(int i = 0; i < MAX; i++) R[i] = i;
}
int find(int v)
{
	if(R[v] != v) R[v] = find(R[v]);
	return R[v];
}
void uni(int u, int v)
{
	R[find(u)] = find(v);
}

int N, M, Q;
vector<int> G[MAX];
bool visited[MAX];

int maxdepth = -1;
int maxv = 0;
void dfs(int u, int p, int d)
{
	visited[u] = true;
	if(d > maxdepth)
	{
		maxdepth = d;
		maxv = u;
	}
	//dfsstack.push_back(u);
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		dfs(v, u, d + 1);
	}
	//dfsstack.pop_back();
}

//vector<int> dfsstack;
/*bool dfs2(int u, int p, int d)
{
	dfsstack.push_back(u);
	if(d == maxdepth) return true;
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		if(dfs(v, u, d + 1)) return true;
	}
	dfsstack.pop_back();
}*/

int diam[MAX];

int main()
{
	cin >> N >> M >> Q;
	reset();
	for(int i = 0; i < M; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
		uni(a, b);
	}
	memset(visited, 0, sizeof(visited));
	for(int u = 1; u <= N; u++)
	{
		if(visited[u]) continue;
		//dfsstack.clear();
		maxdepth = -1;
		dfs(u, -1, 0);
		maxdepth = -1;
		dfs(maxv, -1, 0);
		diam[find(u)] = maxdepth;
		//dfs2(maxv, -1, 0);
	}
	for(int q = 0; q < Q; q++)
	{
		int t;
		scanf("%d", &t);
		if(t == 1)
		{
			int u;
			scanf("%d", &u);
			printf("%d\n", diam[find(u)]);
		}
		else
		{
			int u, v;
			scanf("%d %d", &u, &v);
			int d1 = diam[find(u)], d2 = diam[find(v)];
			uni(u, v);
			diam[find(u)] = (d1 + 1) / 2 + (d2 + 1) / 2 + 1;
		}
	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAX = 300005;
vector<int> G[MAX];

bool vis[MAX];
int maxdepth(int u, int p)
{
	vis[u] = true;
	int best = 0;
	for(int i = 0; i < G[u].size(); i++)
	{
		int v = G[u][i];
		if(v == p) continue;
		best = max(best, maxdepth(v, u) + 1);
	}
	return best;
}

int main()
{
	int N, M, Q;
	cin >> N >> M >> Q;
	for(int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int q = 0; q < Q; q++)
	{
		int t;
		cin >> t;
		if(t == 1)
		{
			int u;
			cin >> u;
			for(int i = 0; i <= N; i++) vis[i] = false;
			maxdepth(u, -1);
			int best = 0;
			for(int i = 0; i <= N; i++)
			{
				if(vis[i])
				{
					//cout << i << ": " << maxdepth(i, -1) << endl;
					best = max(best, maxdepth(i, -1));
				}
			}
			cout << best << '\n';
		}
		else
		{
			int u, v;
			cin >> u >> v;
			for(int i = 0; i <= N; i++) vis[i] = false;
			maxdepth(u, -1);
			if(vis[v]) continue;
			int best = MAX;
			for(int i = 0; i <= N; i++) if(vis[i]) best = min(best, maxdepth(i, -1));
			int besti;
			for(int i = 0; i <= N; i++) if(vis[i]) if(best == maxdepth(i, -1)) besti = i;
			for(int i = 0; i <= N; i++) vis[i] = false;
			maxdepth(v, -1);
			int best2 = MAX;
			for(int i = 0; i <= N; i++) if(vis[i]) best2 = min(best2, maxdepth(i, -1));
			int besti2;
			for(int i = 0; i <= N; i++) if(vis[i]) if(best2 == maxdepth(i, -1)) besti2 = i;
			//cout << besti << '-' << besti2 << endl;
			G[besti].push_back(besti2);
			G[besti2].push_back(besti);
		}
	}
}


#include <bits/stdc++.h>
using namespace std ;
//USUAL
#define s(n) scanf("%d",&n)
#define sp(a,b) scanf("%d %d",&a,&b)
#define sl(n) scanf("%lld",&n)
#define sc(n) scanf("%c",&n)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define forall(i,a,b) for(i=a;i<b;i++)
#define max_const 1000000000
//STL
#define ii pair<int , int >
#define il pair<int , long long int>
#define li pair < long long int , int >
#define mp make_pair
#define vi vector<int>
#define vvi vector< vi >
#define vl vector<long long int>
#define vvl vector< vl >
#define pb push_back
#define tr(it,c) for( typeof ( (c).begin() ) it = c.begin();it!=(c).end();++it)

vvi edge ;
int  visited[300005] = {0} ;
int  component[300005] ;
int  largest[300005] = {0} ;
int  second_largest[300005] = {0} ;
int  diameter[300005] = {0} ;
int size[300005] = {0} ;

void DFS(int v, int root)
{
	//cout<<"Entered "<<v<<endl ;

	visited[v] = 1 ;
	component[v] = root ;
	size[root]++ ;

	tr(it,edge[v])
	{
		if(!visited[*it])
		{
			DFS(*it,root) ;
			if(largest[*it] + 1 > largest[v])
			{
				second_largest[v] = largest[v] ;
				largest[v] = largest[*it] +1 ;
			}
			else if(largest[*it] + 1 >second_largest[v])
			{
				second_largest[v] = largest[*it] + 1 ;
			}

			if(diameter[*it] > diameter[v])
			{
				diameter[v] = diameter[*it]  ;
			}

		}
	}

	if(largest[v] + second_largest[v] > diameter[v])
		diameter[v] = largest[v] + second_largest[v] ;

}

int Find_component(int x)
{
	int y = x;
	while(!(x==component[x]))
	{
		component[x] = component[component[x]] ;
		x = component[x] ;
	}

	component[y] = x ;
	return x ;
}

void merge_tree(int x , int y)
{
	int r1 = Find_component(x) ;
	int r2 = Find_component(y) ;

	if(size[r2] > size[r1])
		swap(r1 , r2) ;

	if(r1==r2)
		return ;

	if(size[r2] > size[r1])
		swap(r1 , r2) ;

	int temp =     (diameter[r1]+1)/2 + (diameter[r2]+1)/2 + 1 ;           //(diameter[r1]%2==0?diameter[r1]/2:diameter[r1]/2 + 1) + (diameter[r2]%2==0?diameter[r2]/2:diameter[r2]/2+1) + 1;

	//diameter[r1] = max(temp , max(diameter[r1] , diameter[r2])) ;

	if(temp > diameter[r1])
	{
		diameter[r1] = temp ;
	}

	if(diameter[r2] > diameter[r1])
	{
		diameter[r1] = diameter[r2] ;
	}

	component[r2] = r1 ;
}

int main()
{
	int n,m,q ;
	s(n) ;
	s(m) ;
	s(q) ;

	edge.resize(n+1) ;

	for(int i=0;i<m;i++)
	{
		int x,y ;
		s(x);
		s(y);

		edge[x].pb(y) ;
		edge[y].pb(x) ;
	}

	/*
	visited.resize(n+1,0) ;
	largest.resize(n+1,0) ;
	second_largest.resize(n+1,0) ;
	diameter.resize(n+1,0) ;
	component.resize(n+1) ;
	*/

	for(int i=1;i<=n;i++)
	{
		if(!visited[i])
		{
			DFS(i,i) ;
		}
	}

	/*for(int i=1;i<=n;i++)
	{
		cout<<i<<"  "<<visited[i]<<"  "<<component[i]<<"  "<<diameter[component[i]]<<endl ;
	}*/

	for(int i=0;i<q;i++)
	{
		int operation ;
		s(operation) ;
		if(operation==1)
		{
			int x ;
			s(x) ;
			int root = Find_component(x) ;
			printf("%d\n",diameter[root] );
			//cout<<diameter[root]<<endl ;
		}
		if(operation==2)
		{
			int x,y ;
			s(x) ;
			s(y) ;
			merge_tree(x , y) ;
		}
	}

	return 0 ;
}


import java.util.*;
public class m{
public static void main(String[]a)
{
    Scanner input = new Scanner(System.in);
    int n = input.nextInt(), m = input.nextInt(), k = input.nextInt();
    boolean win = false;
    for(int i = 0; i<k; i++)
    {
        int x = input.nextInt(), y = input.nextInt();
        int dx = Math.min(x,n-1-x);
        int dy = Math.min(y,m-1-y);
        win |= dx+dy<=4;
    }
    System.out.println(win?"YES":"NO");
}
}


import java.util.*;
public class m{
public static void main(String[]a)
{
    Scanner input = new Scanner(System.in);
    int n = input.nextInt(), m = input.nextInt(), k = input.nextInt();
    boolean win = false;
    for(int i = 0; i<k; i++)
    {
        int x = input.nextInt(), y = input.nextInt();
        int dx = Math.min(x-1,n-x);
        int dy = Math.min(y-1,m-y);
        win |= Math.min(dx,dy)<=4;
    }
    System.out.println(win?"YES":"NO");
}
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class PieOrDie { //Round #51 - Pie or die
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));

		int numRows = sc.nextInt();
		int numCols = sc.nextInt();
		int numPies = sc.nextInt();

		boolean piesWin = false;
		for(int i = 0; i < numPies; i++) {
			int X = sc.nextInt();
			int Y = sc.nextInt();

			if(X <= 3 || X >= numRows - 2 || Y <= 3 || Y >= numCols - 2) {
				piesWin = true;
			}
		}

		if(piesWin) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class PieOrDie { //Round #51 - Pie or die
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));

		int numRows = sc.nextInt();
		int numCols = sc.nextInt();
		int numPies = sc.nextInt();

		boolean piesWin = false;
		for(int i = 0; i < numPies; i++) {
			int X = sc.nextInt();
			int Y = sc.nextInt();

			if(X <= 5 || X >= numRows - 4 || Y <= 5 || Y >= numCols - 4) {
				piesWin = true;
			}
		}

		if(piesWin) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class PieOrDie { //Round #51 - Pie or die
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));

		int numRows = sc.nextInt();
		int numCols = sc.nextInt();
		int numPies = sc.nextInt();

		/*
		int[][] pies = new int[numRows][numCols];
		for(int i = 0; i < numPies; i++) {
			pies[sc.nextInt()-1][sc.nextInt()-1]++;
		}
		*/

		boolean piesWin = false;
		for(int i = 0; i < numPies; i++) {
			int X = sc.nextInt();
			int Y = sc.nextInt();

			if(X == 1 || X == numRows || Y == 1 || Y == numCols) {
				piesWin = true;
			}
		}

		if(piesWin) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author madi
 */
public class Round51C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();

        if (k == 0) {
            System.out.println("NO");
            return;
        }

        int[][] p = new int[k][2];

        for (int i = 0; i < k; i++) {
            p[i][0] = sc.nextInt();
            p[i][1] = sc.nextInt();
        }

        for(int i = 0; i < k; i++) {
            if (p[i][0] <= 4 || p[i][1] <= 4 || n - p[i][0] <= 3 || m - p[i][1] <= 3) {
                System.out.println("YES");
                return;
            }
        }

        System.out.println("NO");
    }
}


import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author madi
 */
public class Round51C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();

        if (k == 0) {
            System.out.println("NO");
            return;
        }

        int[][] p = new int[k][2];

        for (int i = 0; i< k; i++) {
            p[i][0] = sc.nextInt();
            p[i][1] = sc.nextInt();
        }

        for(int i = 0; i < k; i++) {
            if (p[i][0] < 4 || p[i][1] < 4 || n - p[i][0] < 3 || m - p[i][1] < 3) {
                System.out.println("YES");
                return;
            }
        }

        System.out.println("NO");
    }
}


import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author madi
 */
public class Round51C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();

        if (k == 0) {
            System.out.println("NO");
            return;
        }

        int[][] p = new int[k][2];

        for (int i = 0; i < k; i++) {
            p[i][0] = sc.nextInt();
            p[i][1] = sc.nextInt();
        }

        for(int i = 0; i < k; i++) {
            if (p[i][0] <= 5 || p[i][1] <= 5 || n - p[i][0] <= 4 || m - p[i][1] <= 4) {
                System.out.println("YES");
                return;
            }
        }

        System.out.println("NO");
    }
}


import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author madi
 */
public class Round51C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();

        if (k == 0) {
            System.out.println("NO");
            return;
        }

        int[][] p = new int[k][2];

        for (int i = 0; i < k; i++) {
            p[i][0] = sc.nextInt();
            p[i][1] = sc.nextInt();
        }

        for(int i = 0; i < k; i++) {
            if (p[i][0] <= 4 || p[i][1] <= 4 || n - p[i][0] <= 3 || m - p[i][1] <= 3 || p[i][0] == p[i][1]) {
                System.out.println("YES");
                return;
            }
        }

        System.out.println("NO");
    }
}


import java.io.*;
import java.util.*;

public class Solution {

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		if (k == 0) {
			out.println("NO");
			return;
		}
		if (n == 1 || m == 1) {
			out.println("YES");
			return;
		}
		final int[] dx = {-1, 1, 0, 0};
		final int[] dy = {0, 0, -1, 1};
		boolean[][][] win = new boolean[1 << 4][n][m];
		for (int mask = (1 << 4) - 2; mask >= 0; --mask) {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < m; ++j) {
					if (i == 0 && ((mask & 1) == 0 || (mask & 2) == 0)) {
						win[mask][i][j] = true;
					}
					if (i == n - 1 && ((mask & 8) == 0 || (mask & 4) == 0)) {
						win[mask][i][j] = true;
					}
					if (j == 0 && ((mask & 1) == 0 || (mask & 8) == 0)) {
						win[mask][i][j] = true;
					}
					if (j == m - 1 && ((mask & 2) == 0 || (mask & 4) == 0)) {
						win[mask][i][j] = true;
					}
					boolean ok = true;
					loop: for (int f = 0; f < 4; ++f) {
						if ((mask & (1 << f)) == 0) {
							for (int dir = 0; dir < 4; ++dir) {
								int x = i + dx[dir];
								int y = j + dy[dir];
								if (x < 0 || x >= n || y < 0 || y >= m) {
									continue;
								}
								if (win[mask | (1 << f)][x][y]) {
									continue loop;
								}
							}
							ok = false;
							break;
						}
					}
					win[mask][i][j] |= ok;
				}
			}
		}
//		for (int t = 0; t < 1 << 8; ++t) {
//			for (int i = 0; i < n; ++i) {
//				for (int j = 0; j < m; ++j) {
//					System.out.print(win[t][i][j] ? 1 : 0);
//				}
//				System.out.println();
//			}
//			System.out.println();
//		}
		for (int i = 0; i < k; ++i) {
			int x = nextInt() - 1;
			int y = nextInt() - 1;
			if (/*x < 3 || x >= n - 3 || y < 3 || y >= m - 3*/win[0][x][y]) {
				out.println("YES");
				return;
			}
		}
		out.println("NO");
	}

	Solution() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		eat("");

		solve();

		in.close();
		out.close();
	}

	private void eat(String str) {
		st = new StringTokenizer(str);
	}

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) throws IOException {
		new Solution();
	}
}


import java.io.*;
import java.util.*;

public class Solution {

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
//		if (k == 0) {
//			out.println("NO");
//			return;
//		}
//		if (n == 1 || m == 1) {
//			out.println("YES");
//			return;
//		}
//		final int[] dx = {-1, 1, 0, 0};
//		final int[] dy = {0, 0, -1, 1};
//		boolean[][][] win = new boolean[1 << 8][n][m];
//		for (int mask = (1 << 8) - 1; mask >= 0; --mask) {
//			for (int i = 0; i < n; ++i) {
//				for (int j = 0; j < m; ++j) {
//					if (i == 0 && ((mask >> 0) & 3) != 3) {
//						win[mask][i][j] = true;
//					}
//					if (i == n - 1 && ((mask >> 2) & 3) != 3) {
//						win[mask][i][j] = true;
//					}
//					if (j == 0 && ((mask >> 4) & 3) != 3) {
//						win[mask][i][j] = true;
//					}
//					if (j == m - 1 && ((mask >> 6) & 3) != 3) {
//						win[mask][i][j] = true;
//					}
//					boolean ok = true;
//					loop: for (int f = 0; f < 8; ++f) {
//						if ((mask & (1 << f)) != 0) {
//							for (int dir = 0; dir < 4; ++dir) {
//								int x = i + dx[dir];
//								int y = j + dy[dir];
//								if (x < 0 || x >= n || y < 0 || y >= m) {
//									continue;
//								}
//								if (win[mask | (1 << f)][x][y]) {
//									continue loop;
//								}
//							}
//							ok = false;
//							break;
//						}
//					}
//					win[mask][i][j] |= ok;
//				}
//			}
//		}
		for (int i = 0; i < k; ++i) {
			int x = nextInt() - 1;
			int y = nextInt() - 1;
			if (x < 3 || x >= n - 3 || y < 3 || y >= m - 3) {
				out.println("YES");
				return;
			}
		}
		out.println("NO");
	}

	Solution() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		eat("");

		solve();

		in.close();
		out.close();
	}

	private void eat(String str) {
		st = new StringTokenizer(str);
	}

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) throws IOException {
		new Solution();
	}
}


import java.io.*;
import java.util.*;

public class Solution {

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		if (k == 0) {
			out.println("NO");
			return;
		}
		if (n == 1 || m == 1) {
			out.println("YES");
			return;
		}
		final int[] dx = {-1, 1, 0, 0};
		final int[] dy = {0, 0, -1, 1};
		boolean[][][] win = new boolean[1 << 4][n][m];
		for (int mask = (1 << 4) - 2; mask >= 0; --mask) {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < m; ++j) {
					if (i == 0 && ((mask & 1) == 0 || (mask & 2) == 0)) {
						win[mask][i][j] = true;
					}
					if (i == n - 1 && ((mask & 8) == 0 || (mask & 4) == 0)) {
						win[mask][i][j] = true;
					}
					if (j == 0 && ((mask & 1) == 0 || (mask & 8) == 0)) {
						win[mask][i][j] = true;
					}
					if (j == m - 1 && ((mask & 2) == 0 || (mask & 4) == 0)) {
						win[mask][i][j] = true;
					}
					boolean ok = true;
					loop: for (int f = 0; f < 4; ++f) {
						if ((mask & (1 << f)) == 0) {
							for (int dir = 0; dir < 4; ++dir) {
								int x = i + dx[dir];
								int y = j + dy[dir];
								if (x < 0 || x >= n || y < 0 || y >= m) {
									continue;
								}
								if (win[mask | (1 << f)][x][y]) {
									continue loop;
								}
							}
							ok = false;
							break;
						}
					}
					win[mask][i][j] |= ok;
				}
			}
		}
//		for (int t = 0; t < 1 << 8; ++t) {
//			for (int i = 0; i < n; ++i) {
//				for (int j = 0; j < m; ++j) {
//					System.out.print(win[t][i][j] ? 1 : 0);
//				}
//				System.out.println();
//			}
//			System.out.println();
//		}
		for (int i = 0; i < k; ++i) {
			int x = nextInt() - 1;
			int y = nextInt() - 1;
			for (int d = 0; d < 4; ++d) {
				int xx = x + dx[d];
				int yy = y + dy[d];
				if (xx >= 0 && xx < n && yy >= 0 && yy < m && win[0][xx][yy]) {
					out.println("YES");
					return;
				}
			}
		}
		out.println("NO");
	}

	Solution() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		eat("");

		solve();

		in.close();
		out.close();
	}

	private void eat(String str) {
		st = new StringTokenizer(str);
	}

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) throws IOException {
		new Solution();
	}
}


import java.io.*;
import java.util.*;

public class Solution {

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		for (int i = 0; i < k; ++i) {
			int x = nextInt() - 1;
			int y = nextInt() - 1;
			if (x < 3 || x >= n - 3 || y < 3 || y >= m - 3) {
				out.println("YES");
				return;
			}
		}
		out.println("NO");
	}

	Solution() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		eat("");

		solve();

		in.close();
		out.close();
	}

	private void eat(String str) {
		st = new StringTokenizer(str);
	}

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) throws IOException {
		new Solution();
	}
}


import java.io.*;
import java.util.*;

public class Solution {

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		if (k == 0) {
			out.println("NO");
			return;
		}
		if (n == 1 || m == 1) {
			out.println("YES");
			return;
		}
		final int[] dx = {-1, 1, 0, 0};
		final int[] dy = {0, 0, -1, 1};
		boolean[][][] win = new boolean[1 << 8][n][m];
		for (int mask = (1 << 8) - 2; mask >= 0; --mask) {
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < m; ++j) {
					if (i == 0 && ((mask >> 0) & 3) != 3) {
						win[mask][i][j] = true;
					}
					if (i == n - 1 && ((mask >> 2) & 3) != 3) {
						win[mask][i][j] = true;
					}
					if (j == 0 && ((mask >> 4) & 3) != 3) {
						win[mask][i][j] = true;
					}
					if (j == m - 1 && ((mask >> 6) & 3) != 3) {
						win[mask][i][j] = true;
					}
					boolean ok = true;
					loop: for (int f = 0; f < 8; ++f) {
						if ((mask & (1 << f)) == 0) {
							for (int dir = 0; dir < 4; ++dir) {
								int x = i + dx[dir];
								int y = j + dy[dir];
								if (x < 0 || x >= n || y < 0 || y >= m) {
									continue;
								}
								if (win[mask | (1 << f)][x][y]) {
									continue loop;
								}
							}
							ok = false;
							break;
						}
					}
					win[mask][i][j] |= ok;
				}
			}
		}
//		for (int t = 0; t < 1 << 8; ++t) {
//			for (int i = 0; i < n; ++i) {
//				for (int j = 0; j < m; ++j) {
//					System.out.print(win[t][i][j] ? 1 : 0);
//				}
//				System.out.println();
//			}
//			System.out.println();
//		}
		for (int i = 0; i < k; ++i) {
			int x = nextInt() - 1;
			int y = nextInt() - 1;
			if (/*x < 3 || x >= n - 3 || y < 3 || y >= m - 3*/win[0][x][y]) {
				out.println("YES");
				return;
			}
		}
		out.println("NO");
	}

	Solution() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		eat("");

		solve();

		in.close();
		out.close();
	}

	private void eat(String str) {
		st = new StringTokenizer(str);
	}

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) throws IOException {
		new Solution();
	}
}


import java.io.*;
import java.util.*;

public class Solution {

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		for (int i = 0; i < k; ++i) {
			int x = nextInt() - 1;
			int y = nextInt() - 1;
			if (x < 5 || x >= n - 5 || y < 5 || y >= m - 5) {
				out.println("YES");
				return;
			}
		}
		out.println("NO");
	}

	Solution() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		eat("");

		solve();

		in.close();
		out.close();
	}

	private void eat(String str) {
		st = new StringTokenizer(str);
	}

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) throws IOException {
		new Solution();
	}
}


import java.io.*;
import java.util.*;
import java.math.*;

public class C implements Runnable {

	void solve() {
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < k; i++) {
			int x = nextInt() - 1;
			int y = nextInt() - 1;
			min = Math.min(min, x);
			min = Math.min(min, y);
			min = Math.min(min, n - x - 1);
			min = Math.min(min, m - y - 1);
		}
		if (min < 5) {
			out.println("YES");
		} else {
			out.println("NO");
		}
	}

	FastScanner sc;
	PrintWriter out;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			sc = new FastScanner(System.in);
			out = new PrintWriter(System.out);
			solve();
			sc.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	int nextInt() {
		return sc.nextInt();
	}

	String nextToken() {
		return sc.nextToken();
	}

	long nextLong() {
		return sc.nextLong();
	}

	double nextDouble() {
		return sc.nextDouble();
	}

	BigInteger nextBigInteger() {
		return sc.nextBigInteger();
	}

	class FastScanner extends BufferedReader {
		StringTokenizer st;
		boolean eof;
		String buf;
		String curLine;
		boolean createST;

		public FastScanner(String fileName) throws FileNotFoundException {
			this(fileName, true);
		}

		public FastScanner(String fileName, boolean createST)
				throws FileNotFoundException {
			super(new FileReader(fileName));
			this.createST = createST;
			nextToken();
		}

		public FastScanner(InputStream stream) {
			this(stream, true);
		}

		public FastScanner(InputStream stream, boolean createST) {
			super(new InputStreamReader(stream));
			this.createST = createST;
			nextToken();
		}

		String nextLine() {
			String ret = curLine;
			if (createST) {
				st = null;
			}
			nextToken();
			return ret;
		}

		String nextToken() {
			if (!createST) {
				try {
					curLine = readLine();
				} catch (Exception e) {
					eof = true;
				}
				return null;
			}
			while (st == null || !st.hasMoreTokens()) {
				try {
					curLine = readLine();
					st = new StringTokenizer(curLine);
				} catch (Exception e) {
					eof = true;
					break;
				}
			}
			String ret = buf;
			buf = eof ? "-1" : st.nextToken();
			return ret;
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}

		BigInteger nextBigInteger() {
			return new BigInteger(nextToken());
		}

		public void close() {
			try {
				buf = null;
				st = null;
				curLine = null;
				super.close();
			} catch (Exception e) {

			}
		}

		boolean isEOF() {
			return eof;
		}
	}

	public static void main(String[] args) {
		new C().run();
	}
}


import java.util.*;

public class C
{
   public static void main(String[] args)
   {
      new C(new Scanner(System.in));
   }

   public C(Scanner in)
   {
      int W = in.nextInt();
      int H = in.nextInt();
      int k = in.nextInt();

      boolean passed = false;
      for (int i=0; i<k; i++)
      {
         int x = in.nextInt();
         int y = in.nextInt();
         int dist = Math.min(x, y);
         dist = Math.min(W-x+1, dist);
         dist = Math.min(H-y+1, dist);
         if (dist < 5)
            passed = true;
      }

      if (passed)
         System.out.println("YES");
      else
         System.out.println("NO");
   }
}


import java.util.*;

public class C
{
   public static void main(String[] args)
   {
      new C(new Scanner(System.in));
   }

   public C(Scanner in)
   {
      int W = in.nextInt();
      int H = in.nextInt();
      int k = in.nextInt();

      boolean passed = false;
      for (int i=0; i<k; i++)
      {
         int x = in.nextInt();
         int y = in.nextInt();
         int dist = Math.min(x, y);
         dist = Math.min(W-x+1, dist);
         dist = Math.min(H-y+1, dist);
         if (dist <= 5)
            passed = true;
      }

      if (passed)
         System.out.println("YES");
      else
         System.out.println("NO");
   }
}


import java.util.*;

public class C
{
   public static void main(String[] args)
   {
      new C(new Scanner(System.in));
   }

   public C(Scanner in)
   {
      int W = in.nextInt();
      int H = in.nextInt();
      int k = in.nextInt();

      boolean passed = false;
      for (int i=0; i<k; i++)
      {
         int x = in.nextInt();
         int y = in.nextInt();
         int dist = Math.min(x, y);
         dist = Math.min(W-x, dist);
         dist = Math.min(H-y, dist);
         if (dist <= 5)
            passed = true;
      }

      if (passed)
         System.out.println("YES");
      else
         System.out.println("NO");
   }
}


import java.util.*;

public class C
{
   public static void main(String[] args)
   {
      new C(new Scanner(System.in));
   }

   public C(Scanner in)
   {
      int W = in.nextInt();
      int H = in.nextInt();
      int k = in.nextInt();

      boolean passed = false;
      for (int i=0; i<k; i++)
      {
         int x = in.nextInt();
         int y = in.nextInt();
         int dist = Math.min(x, y);
         dist = Math.min(W-x, dist);
         dist = Math.min(H-y, dist);
         if (dist < 5)
            passed = true;
      }

      if (passed)
         System.out.println("YES");
      else
         System.out.println("NO");
   }
}


import java.util.*;

public class C
{
   public static void main(String[] args)
   {
      new C(new Scanner(System.in));
   }

   public C(Scanner in)
   {
      int n = in.nextInt();
      int m = in.nextInt();
      int k = in.nextInt();

      for (int i=0; i<k; i++)
      {
         int x = in.nextInt();
         int y = in.nextInt();
         if ((x == 1)||(x == n)||(y == 1)||(y == m))
         {
            System.out.println("YES");
            return;
         }
      }

      System.out.println("NO");
   }
}


import java.util.*;

public class C
{
   public static void main(String[] args)
   {
      new C(new Scanner(System.in));
   }

   public C(Scanner in)
   {
      int W = in.nextInt();
      int H = in.nextInt();
      int k = in.nextInt();

      boolean passed = false;
      for (int i=0; i<k; i++)
      {
         int x = in.nextInt();
         int y = in.nextInt();
         int dist = (x-1);
         dist = Math.min(y-1, dist);
         dist = Math.min(W-x, dist);
         dist = Math.min(H-y, dist);
         if (dist <= 5)
            passed = true;
      }

      if (passed)
         System.out.println("YES");
      else
         System.out.println("NO");
   }
}


import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();
        boolean[][] A = new boolean[n][m];
        for (int i = 0; i < k; i++)
            A[in.nextInt() - 1][in.nextInt() - 2] = true;
        boolean can = false;
        for (int i = 0; i < Math.min(n, 3); i++)
            for (int j = 0; j < m; j++)
                can |= A[i][j];
        for (int i = n - 1; i >= Math.max(0, n - 3); i--)
            for (int j = 0; j < m; j++)
                can |= A[i][j];
        for (int i = 0; i < Math.min(m, 3); i++)
            for (int j = 0; j < n; j++)
                can |= A[j][i];
        for (int i = m - 1; i >= Math.max(0, m - 3); i--)
            for (int j = 0; j < n; j++)
                can |= A[j][i];
        if (can)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();
        boolean[][] A = new boolean[n][m];
        for (int i = 0; i < k; i++)
            A[in.nextInt() - 1][in.nextInt() - 2] = true;
        boolean can = false;
        for (int i = 0; i < Math.min(n, 5); i++)
            for (int j = 0; j < m; j++)
                can |= A[i][j];
        for (int i = n - 1; i >= Math.max(0, n - 5); i--)
            for (int j = 0; j < m; j++)
                can |= A[i][j];
        for (int i = 0; i < Math.min(m, 5); i++)
            for (int j = 0; j < n; j++)
                can |= A[j][i];
        for (int i = m - 1; i >= Math.max(0, m - 5); i--)
            for (int j = 0; j < n; j++)
                can |= A[j][i];
        if (can)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();
        boolean[][] A = new boolean[n][m];
        for (int i = 0; i < k; i++)
            A[in.nextInt() - 1][in.nextInt() - 1] = true;
        boolean can = false;
        for (int i = 0; i < Math.min(n, 5); i++)
            for (int j = 0; j < m; j++)
                can |= A[i][j];
        for (int i = n - 1; i >= Math.max(0, n - 5); i--)
            for (int j = 0; j < m; j++)
                can |= A[i][j];
        for (int i = 0; i < Math.min(m, 5); i++)
            for (int j = 0; j < n; j++)
                can |= A[j][i];
        for (int i = m - 1; i >= Math.max(0, m - 5); i--)
            for (int j = 0; j < n; j++)
                can |= A[j][i];
        if (can)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();
        boolean[][] A = new boolean[n][m];
        for (int i = 0; i < k; i++)
            A[in.nextInt() - 1][in.nextInt() - 2] = true;
        boolean can = false;
        for (int i = 0; i < Math.min(n, 4); i++)
            for (int j = 0; j < m; j++)
                can |= A[i][j];
        for (int i = n - 1; i >= Math.max(0, n - 4); i--)
            for (int j = 0; j < m; j++)
                can |= A[i][j];
        for (int i = 0; i < Math.min(m, 4); i++)
            for (int j = 0; j < n; j++)
                can |= A[j][i];
        for (int i = m - 1; i >= Math.max(0, m - 4); i--)
            for (int j = 0; j < n; j++)
                can |= A[j][i];
        if (can)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


import java.io.*;

public class C {

	public static void main(String[] args) throws IOException {
		int n = nextInt(), m = nextInt();
		int k = nextInt();
		for (int i = 0; i < k; i++) {
			int x = nextInt(), y = nextInt();
			if (x <= 5 || y <= 5 || x >= n - 4 || y >= m - 4) {
				System.out.println("YES");
				return;
			}
		}
		System.out.println("NO");
	}

	static int nextInt() throws IOException {
		int m = 0;
		int c = System.in.read();
		while (c < '0' || c > '9')
			c = System.in.read();
		while (c >= '0' && c <= '9') {
			m = m * 10 + (c - '0');
			c = System.in.read();
		}
		return m;
	}
}


import java.io.* ;
import java.util.* ;
import java.math.* ;

public class Main
{
    public static void main( String args[] ) {
        Scanner Input = new Scanner( System.in ) ;
		int N = Input.nextInt() ;
		int M = Input.nextInt() ;
		int K = Input.nextInt() ;
		String Ret = "NO" ;
		for ( ; K -- > 0 ; ) {
			int X = Input.nextInt() ;
			int Y = Input.nextInt() ;
			if ( X <= 5 || N - X + 1 <= 5 || Y <= 5 || M - Y + 1 <= 5 )
				Ret = "YES" ;
		}
		System.out.println( Ret ) ;
    }
}


//package round51;

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class C {
	Scanner in;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int m = ni();
		int k = ni();
		if(k == 0){
			out.println("NO");
			return;
		}

		int mind = 99999999;
		for(int i = 0;i < k;i++){
			int r = ni() - 1;
			int c = ni() - 1;

			mind = Math.min(Math.min(r, n - 1 - r), Math.min(c, m - 1 - c));
		}
		if(mind <= 4){
			out.println("YES");
		}else{
			out.println("NO");
		}
	}

	void run() throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		solve();
		out.flush();
	}

	public static void main(String[] args) throws Exception
	{
		new C().run();
	}

	int ni() { return Integer.parseInt(in.next()); }
	void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


//package round51;

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class C {
	Scanner in;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int m = ni();
		int k = ni();
		if(k == 0){
			out.println("NO");
			return;
		}

		int mind = 99999999;
		for(int i = 0;i < k;i++){
			int r = ni() - 1;
			int c = ni() - 1;

			mind = Math.min(mind, Math.min(Math.min(r, n - 1 - r), Math.min(c, m - 1 - c)));
		}
		if(mind <= 4){
			out.println("YES");
		}else{
			out.println("NO");
		}
	}

	void run() throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		solve();
		out.flush();
	}

	public static void main(String[] args) throws Exception
	{
		new C().run();
	}

	int ni() { return Integer.parseInt(in.next()); }
	void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ProblemC {

    static int[][] board;

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] num = in.readLine().split(" ");
        int n = Integer.parseInt(num[0]);
        int m = Integer.parseInt(num[1]);
        int k = Integer.parseInt(num[2]);
        board = new int[n+1][m+1];

        int closest = Integer.MAX_VALUE;
        for(int i = 0; i < k; ++i) {
            num = in.readLine().split(" ");
            int x = Integer.parseInt(num[0]);
            int y = Integer.parseInt(num[1]);
            ++board[x][y];

            //number moves to reach border
            int toTop = x-1;
            int toBottom = n-x;
            int toLeft = y-1;
            int toRight = m-y;
            int best = Math.min(Math.min(Math.min(toTop,toBottom),toLeft),toRight);
            closest = Math.min(closest,best);
        }

        //if move pie that is further from border, then just giving other player more time to block corners
        if(closest <= 4) System.out.println("YES");
        else System.out.println("NO");

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ProblemC {

    static int[][] board;

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] num = in.readLine().split(" ");
        int n = Integer.parseInt(num[0]);
        int m = Integer.parseInt(num[1]);
        int k = Integer.parseInt(num[2]);
        board = new int[n+1][m+1];

        int closest = Integer.MAX_VALUE;
        for(int i = 0; i < k; ++i) {
            num = in.readLine().split(" ");
            int x = Integer.parseInt(num[0]);
            int y = Integer.parseInt(num[1]);
            ++board[x][y];

            //number moves to reach border
            int toTop = x-1;
            int toBottom = n-x;
            int toLeft = y-1;
            int toRight = m-y;
            int best = Math.min(Math.min(Math.min(toTop,toBottom),toLeft),toRight);
            closest = Math.min(closest,best);
        }

        //if move pie that is further from border, then just giving other player more time to block corners
        if(closest <= 5) System.out.println("YES");
        else System.out.println("NO");

    }

}


import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int i,j;
        int x,y;
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        int magic=4;

        for(i=0;i<k;i++) {
            x=in.nextInt();
            y=in.nextInt();

            if(x-1<magic || y-1<magic || n-x<magic || m-y<magic) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}


import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int i,j;
        int x,y;
        int n=in.nextInt(),m=in.nextInt(),k=in.nextInt();
        int magic=4;

        for(i=0;i<k;i++) {
            x=in.nextInt();
            y=in.nextInt();

            if(x-1<=magic || y-1<=magic || n-x<=magic || m-y<=magic) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}


import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int pies=sc.nextInt();
        boolean win=false;
        for(int i=0;i<pies;i++){
            int r=sc.nextInt();
            int c=sc.nextInt();
            if(Math.abs(r-1)<=4||Math.abs(r-n)<=4||Math.abs(c-1)<=4||Math.abs(c-m)<=4)
                win=true;
        }
        if(win) System.out.println("YES");
        else System.out.println("NO");
    }
}


import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int pies=sc.nextInt();
        boolean win=false;
        for(int i=0;i<pies;i++){
            int r=sc.nextInt();
            int c=sc.nextInt();
            if(Math.abs(r-1)<=2||Math.abs(r-n)<=2||Math.abs(c-1)<=2||Math.abs(c-m)<=2) win=true;
        }
        if(win) System.out.println("YES");
        else System.out.println("NO");
    }
}


import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int pies=sc.nextInt();
        boolean win=false;
        for(int i=0;i<pies;i++){
            int r=sc.nextInt();
            int c=sc.nextInt();
            if(Math.abs(r-1)<=2||Math.abs(r-n)<=2||Math.abs(c-1)<=2||Math.abs(c-m)<=2
                    ||Math.max(Math.abs(r-1),Math.abs(c-m))<=3||
                    Math.max(Math.abs(r-n),Math.abs(c-m))<=3||
                    Math.max(Math.abs(r-n),Math.abs(c-1))<=3||
                    Math.max(Math.abs(r-1),Math.abs(c-1))<=3)
                win=true;
        }
        if(win) System.out.println("YES");
        else System.out.println("NO");
    }
}


import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int pies=sc.nextInt();
        boolean win=false;
        for(int i=0;i<pies;i++){
            int r=sc.nextInt();
            int c=sc.nextInt();
            if(r==1||r==n||r==2||r==n-1||c==1||c==m||c==2||c==m-1) win=true;
        }
        if(win) System.out.println("YES");
        else System.out.println("NO");
    }
}


//package round51;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {

	static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
	static PrintWriter out = new PrintWriter(System.out);

	static String nextToken() throws IOException{
		while (st==null || !st.hasMoreTokens()){
			String s = bf.readLine();
			if (s == null)
				return null;
			st = new StringTokenizer(s);
		}

		return st.nextToken();
	}

	static int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}

	public static void main(String[] args) throws IOException{
		int n = nextInt(),
			m = nextInt(),
			k = nextInt();

		for (int i=0; i<k; i++){
			int x = nextInt(),
				y = nextInt();

			int dx = Math.min(x-1, n-x);
			int dy = Math.min(y-1, m-y);
			int d = Math.min(dx, dy);

			if (d < 5){
				out.println("YES");
				out.flush();
				return;
			}
		}

		out.println("NO");
		out.flush();
	}

}


//package round51;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {

	static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
	static PrintWriter out = new PrintWriter(System.out);

	static String nextToken() throws IOException{
		while (st==null || !st.hasMoreTokens()){
			String s = bf.readLine();
			if (s == null)
				return null;
			st = new StringTokenizer(s);
		}

		return st.nextToken();
	}

	static int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}

	public static void main(String[] args) throws IOException{
		int n = nextInt(),
			m = nextInt(),
			k = nextInt();

		for (int i=0; i<k; i++){
			int x = nextInt(),
				y = nextInt();

			int dx = Math.min(x-1, n-x);
			int dy = Math.min(y-1, m-y);
			int d = Math.min(dx, dy);

			if (d < 9){
				out.println("YES");
				out.flush();
				return;
			}
		}

		out.println("NO");
		out.flush();
	}

}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class ProblemC_51 {

	final boolean ONLINE_JUDGE=System.getProperty("ONLINE_JUDGE")!=null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok=new StringTokenizer("");

	void init() throws FileNotFoundException{
		if (ONLINE_JUDGE){
			in=new BufferedReader(new InputStreamReader(System.in));
			out =new PrintWriter(System.out);
		}
		else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

	String readString() throws IOException{
		while(!tok.hasMoreTokens()){
			tok=new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException{
		return Integer.parseInt(readString());
	}

	public static void main(String[] args){
		new ProblemC_51().run();
	}

	public void run(){
		try{
			long t1=System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2=System.currentTimeMillis();
			System.err.println("Time = "+(t2-t1));
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	void solve() throws IOException{
		int n=readInt();
		int m=readInt();
		int k=readInt();
		for (int i=0; i<k; i++){
			int x=readInt();
			int y=readInt();
			if (min(x-1,min(y-1,min(n-x,m-y)))<5){
				out.print("YES");
				return;
			}
		}
		out.print("NO");
	}
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class ProblemC_51 {

	final boolean ONLINE_JUDGE=System.getProperty("ONLINE_JUDGE")!=null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok=new StringTokenizer("");

	void init() throws FileNotFoundException{
		if (ONLINE_JUDGE){
			in=new BufferedReader(new InputStreamReader(System.in));
			out =new PrintWriter(System.out);
		}
		else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

	String readString() throws IOException{
		while(!tok.hasMoreTokens()){
			tok=new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException{
		return Integer.parseInt(readString());
	}

	public static void main(String[] args){
		new ProblemC_51().run();
	}

	public void run(){
		try{
			long t1=System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2=System.currentTimeMillis();
			System.err.println("Time = "+(t2-t1));
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	void solve() throws IOException{
		int n=readInt();
		int m=readInt();
		int k=readInt();
		for (int i=0; i<k; i++){
			int x=readInt();
			int y=readInt();
			if (min(x,min(y,min(n-x,m-y)))<6){
				out.print("YES");
				return;
			}
		}
		out.print("NO");
	}
}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Solution55C {

        final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;
        BufferedReader in;
        PrintWriter out;
        StringTokenizer tok = new StringTokenizer("");

        void init() throws FileNotFoundException{
                if (ONLINE_JUDGE){
                        in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
                }else{
                        in = new BufferedReader(new FileReader("input.txt"));
                        out = new PrintWriter("output.txt");
                }
        }

        String readString() throws IOException{
                while(!tok.hasMoreTokens()){
                        tok = new StringTokenizer(in.readLine());
                }
                return tok.nextToken();
        }

        int readInt() throws IOException{
                return Integer.parseInt(readString());
        }

        long readLong() throws IOException{
                return Long.parseLong(readString());
        }

        double readDouble() throws IOException{
                return Double.parseDouble(readString());
        }

        public static void main(String[] args){
                new Solution55C().run();
        }

        public void run(){
                try{
                        long t1 = System.currentTimeMillis();
                        init();
                        solve();
                        out.close();
                        long t2 = System.currentTimeMillis();
                        System.err.println("Time = "+(t2-t1));
                }catch (Exception e){
                        e.printStackTrace(System.err);
                        System.exit(-1);
                }
        }

        static class Utils {

                private Utils() {}

                public static void mergeSort(int[] a) {
                        mergeSort(a, 0, a.length - 1);
                }

                private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
                        final int MAGIC_VALUE = 50;
                        if (leftIndex < rightIndex) {
                                if (rightIndex - leftIndex <= MAGIC_VALUE) {
                                        insertionSort(a, leftIndex, rightIndex);
                                } else {
                                        int middleIndex = (leftIndex + rightIndex) / 2;
                                        mergeSort(a, leftIndex, middleIndex);
                                        mergeSort(a, middleIndex + 1, rightIndex);
                                        merge(a, leftIndex, middleIndex, rightIndex);
                                }
                        }
                }

                private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
                        int length1 = middleIndex - leftIndex + 1;
                        int length2 = rightIndex - middleIndex;
                        int[] leftArray = new int[length1];
                        int[] rightArray = new int[length2];
                        System.arraycopy(a, leftIndex, leftArray, 0, length1);
                        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
                        for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
                                if (i == length1) {
                                        a[k] = rightArray[j++];
                                } else if (j == length2) {
                                        a[k] = leftArray[i++];
                                } else {
                                        a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
                                }
                        }
                }

                private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
                        for (int i = leftIndex + 1; i <= rightIndex; i++) {
                                int current = a[i];
                                int j = i - 1;
                                while (j >= leftIndex && a[j] > current) {
                                        a[j + 1] = a[j];
                                        j--;
                                }
                                a[j + 1] = current;
                        }
                }
        }

        void solve() throws IOException{
        	int m = readInt();
        	int n = readInt();
        	int k = readInt();
        	int minX = m + 1, maxX = -1, minY = n + 1, maxY = -1;
        	for(int i = 0; i < k; i++){
        		int a = readInt();
        		int b = readInt();
        		minX = min(minX, a);
        		maxX = max(maxX, a);
        		minY = min(minY, b);
        		maxY = max(maxY, b);
        	}
        	if((k > 0) && (minX <= 5 || minY <= 5 || maxX >= m - 4 || maxY >= n - 4))
        		out.println("YES");
        	else out.println("NO");
        }

        static double distance(long x1, long y1, long x2, long y2){
        	return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        }

        static long gcd(long a, long b){
        	while(a != b){
        		if(a < b) a -=b;
        		else b -= a;
        	}
        	return a;
        }

        static long lcm(long a, long b){
        	return a * b /gcd(a, b);
        }
}


/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 1/17/11
 * Time: 1:53 AM
 * To change this template use File | Settings | File Templates.
 */
public class PieDie {

    void run(){
		int N = nextInt(), M = nextInt(), K = nextInt();

		boolean win = false;
		for(int i = 0; i < K; i++){
			int x = nextInt(), y = nextInt();
			if(x <= 5 || y <= 5 || x >= N - 4 || y >= M - 4)
				win = true;
		}

		if(win) System.out.println("YES");
		else System.out.println("NO");
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new PieDie().run();
    }
}


import java.io.*;
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	int N;
	int M;
	int K;
	char[][] map;

	int[] cx;
	int[] cy;

	int[] cornx = new int [4];
	int[] corny = new int [4];

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		N = nextInt();
		M = nextInt();

		K = nextInt();
		map = new char [N][M];
		cx = new int [K];
		cy = new int [K];
		for (int i = 0; i < K; i++) {
			cx[i] = nextInt() - 1;
			cy[i] = nextInt() - 1;
			map[cx[i]][cy[i]] = '*';
		}

		cornx[1] = N - 1;
		corny[1] = 0;
		cornx[2] = 0;
		corny[2] = M - 1;
		cornx[3] = N - 1;
		corny[3] = M - 1;

		dist = new int [N][M];
		queue = new ArrayDeque<Integer> (N * M);
		cdist = new int [4][N][M];
		for (int i = 0; i < 4; i++)
			cbfs(i);
		for (int i = 0; i < K; i++) {
			if (can(i)) {
				out.println("YES");
				out.close();
				return;
			}
		}

		out.println("NO");
		out.close();
	}

	int[][] dist;
	int[][][] cdist;

	Queue<Integer> queue;

	int[] dx = { -1, 0, 1, 0};
	int[] dy = { 0, -1, 0, 1};

	boolean can(int cake) {
		int x = cx[cake];
		int y = cy[cake];
		bfs(x, y);

		for (int cx = 0; cx < N; cx++) {
			if (win(cx, 0))
				return true;
			if (win(cx, M - 1))
				return true;
		}

		for (int cy = 0; cy < M; cy++) {
			if (win(0, cy))
				return true;
			if (win(N - 1, cy))
				return true;
		}

		return false;
	}

	boolean win(int x, int y) {
		if (dist[x][y] == -1)
			return false;
		int d = dist[x][y];
		if (d == 0)
			return true;
		int dr = d - 1;
		int cr = 0;
		for (int i = 0; i < 4; i++)
			if (cdist[i][x][y] != -1)
				cr++;
//		if (d == 1 && cr > 0)
//			return true;
		if (dr < cr)
			return true;
		return false;
	}

	void bfs(int x, int y) {
		for (int[] a : dist)
			fill(a, -1);
		dist[x][y] = 0;
		queue.clear();
		queue.add(x * 100 + y);

		while (!queue.isEmpty()) {
			int state = queue.poll();
			int cx = state / 100;
			int cy = state % 100;
			for (int d = 0; d < dx.length; d++) {
				int nx = cx + dx[d];
				int ny = cy + dy[d];
				if (good(nx, ny)) {
					dist[nx][ny] = dist[cx][cy] + 1;
					queue.add(nx * 100 + ny);
				}
			}
		}
	}

	void cbfs(int corner) {
		int x = cornx[corner];
		int y = corny[corner];
		int[][] dist = cdist[corner];
		for (int[] a : dist)
			fill(a, -1);

		dist[x][y] = 0;
		queue.clear();
		queue.add(x * 100 + y);

		while (!queue.isEmpty()) {
			int state = queue.poll();
			int cx = state / 100;
			int cy = state % 100;
			for (int d = 0; d < dx.length; d++) {
				int nx = cx + dx[d];
				int ny = cy + dy[d];
				if (cgood(nx, ny) && dist[nx][ny] == -1) {
					dist[nx][ny] = dist[cx][cy] + 1;
					queue.add(nx * 100 + ny);
				}
			}
		}
	}

	boolean cgood(int x, int y) {
		return 0 <= x && x < N && 0 <= y && y < M && map[x][y] != '*' && (x == 0 || y == 0 || x == N - 1 || y == M - 1);
	}

	boolean good(int x, int y) {
		return 0 <= x && x < N && 0 <= y && y < M && map[x][y] != '*' && dist[x][y] == -1;
	}

	String nextToken() throws IOException {
		while (!st.hasMoreTokens()) {
			st = new StringTokenizer(in.readLine());
		}

		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();

			if (s == null) {
				return true;
			}

			st = new StringTokenizer(s);
		}

		return false;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Contest51_3 {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] s = in.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int m = Integer.parseInt(s[1]);
        int k = Integer.parseInt(s[2]);
        for (int i = 0; i < k; i++) {
            s = in.readLine().split(" ");
            int x = Integer.parseInt(s[0]);
            int y = Integer.parseInt(s[1]);
            if(x==1 || x==2 || x==3 || x==4 || x==n || x==n-1 || x==n-2 || x==n-3 || x==n-4
             || y==1 || y==2 || y==3 || y==4 || y==m || y==m-1 || y==m-2 || y==m-3 || y==m-4){
                System.out.println("YES");
                return;
            }
        }
            System.out.println("NO");
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Contest51_3 {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] s = in.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int m = Integer.parseInt(s[1]);
        int k = Integer.parseInt(s[2]);
        for (int i = 0; i < k; i++) {
            s = in.readLine().split(" ");
            int x = Integer.parseInt(s[0]);
            int y = Integer.parseInt(s[1]);
            if(x==1 || x==2 || x==3 || x==4 || x==5 || x==n || x==n-1 || x==n-2 || x==n-3 || x==n-4 || x==n-5
             || y==1 || y==2 || y==3 || y==4 || y==5 || y==m || y==m-1 || y==m-2 || y==m-3 || y==m-4 || y==m-5){
                System.out.println("YES");
                return;
            }
        }
            System.out.println("NO");
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Contest51_3 {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] s = in.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int m = Integer.parseInt(s[1]);
        int k = Integer.parseInt(s[2]);
        for (int i = 0; i < k; i++) {
            s = in.readLine().split(" ");
            int x = Integer.parseInt(s[0]);
            int y = Integer.parseInt(s[1]);
            if(x==1 || x==2 || x==3 || x==4 || x==5 || x==n || x==n-1 || x==n-2 || x==n-3 || x==n-4
             || y==1 || y==2 || y==3 || y==4 || y==5 || y==m || y==m-1 || y==m-2 || y==m-3 || y==m-4){
                System.out.println("YES");
                return;
            }
        }
            System.out.println("NO");
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Contest51_3 {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] s = in.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int m = Integer.parseInt(s[1]);
        int k = Integer.parseInt(s[2]);
        for (int i = 0; i < k; i++) {
            s = in.readLine().split(" ");
            int x = Integer.parseInt(s[0]);
            int y = Integer.parseInt(s[1]);
            if(x==1 || x==2 || x==3 || x==4 || x==n || x==n-1 || x==n-2 || x==n-3 || x==n-4
             || y==1 || y==2 || y==3 || y==4 || y==m || x==m-1 || x==m-2 || x==m-3 || x==m-4){
                System.out.println("YES");
                return;
            }
        }
            System.out.println("NO");
    }
}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class BetaRound51_C implements Runnable {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws IOException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	@Override
	public void run() {
		try {
			long t1 = System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2 = System.currentTimeMillis();
			System.err.println("Time = " + (t2 - t1));
		} catch (Exception e) {
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	public static void main(String[] args) {
		new Thread(new BetaRound51_C()).start();
	}

	void solve() throws IOException {
		int n = readInt();
		int m = readInt();
		int k = readInt();
		if (k == 0) {
			out.print("NO");
			return;
		}
		int[] x = new int[k];
		int[] y = new int[k];
		for (int i = 0; i < k; i++) {
			x[i] = readInt();
			y[i] = readInt();
		}
		for (int i = 0; i < k; i++) {
			int dx = min(x[i], n - x[i] + 1);
			int dy = min(y[i], m - y[i] + 1);
			int d = min(dx, dy);
			if (d <= 5) {
				out.print("YES");
				return;
			}
		}
		out.print("NO");
	}

}


import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class BetaRound51_C implements Runnable {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws IOException {
		if (ONLINE_JUDGE) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	@Override
	public void run() {
		try {
			long t1 = System.currentTimeMillis();
			init();
			solve();
			out.close();
			long t2 = System.currentTimeMillis();
			System.err.println("Time = " + (t2 - t1));
		} catch (Exception e) {
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	public static void main(String[] args) {
		new Thread(new BetaRound51_C()).start();
	}

	void solve() throws IOException {
		int n = readInt();
		int m = readInt();
		int k = readInt();
		if (k == 0) {
			out.print("NO");
			return;
		}
		int[] x = new int[k];
		int[] y = new int[k];
		for (int i = 0; i < k; i++) {
			x[i] = readInt();
			y[i] = readInt();
		}
		for (int i = 0; i < k; i++) {
			int dx = min(x[i], n - x[i] + 1);
			int dy = min(y[i], n - y[i] + 1);
			int d = min(dx, dy);
			if (d <= 3) {
				out.print("YES");
				return;
			}
		}
		out.print("NO");
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.HashMap;

public class Main {
    private static StreamTokenizer in;
    private static PrintWriter out;
    private static BufferedReader inB;

    private static int nextInt() throws Exception{
        in.nextToken();
        return (int)in.nval;
    }

    private static String nextString() throws Exception{
        in.nextToken();
        return in.sval;
    }

    static{
        inB = new BufferedReader(new InputStreamReader(System.in));
        in = new StreamTokenizer(inB);
        out = new PrintWriter(System.out);
    }

    public static void main(String[] args)throws Exception {
        int n = nextInt(), m = nextInt(), k = nextInt();

        int min = Integer.MAX_VALUE;
        for(int i = 0; i<k; i++) {
            int x = nextInt()-1, y = nextInt()-1;
            int d = Integer.MAX_VALUE;
            if(n - x < d)d = n-x;
            if(x < d)d = x;
            if(m - y < d)d = m-y;
            if(y < d)d = y;
            if(d < min)min = d;
        }

        System.out.println(min >= 6 ? "NO" : "YES"); /*Magic, 6 == 2 + 4*/
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.HashMap;

public class Main {
    private static StreamTokenizer in;
    private static PrintWriter out;
    private static BufferedReader inB;

    private static int nextInt() throws Exception{
        in.nextToken();
        return (int)in.nval;
    }

    private static String nextString() throws Exception{
        in.nextToken();
        return in.sval;
    }

    static{
        inB = new BufferedReader(new InputStreamReader(System.in));
        in = new StreamTokenizer(inB);
        out = new PrintWriter(System.out);
    }

    public static void main(String[] args)throws Exception {
        int n = nextInt(), m = nextInt(), k = nextInt();

        int min = Integer.MAX_VALUE;
        for(int i = 0; i<k; i++) {
            int x = nextInt()-1, y = nextInt()-1;
            int d = Integer.MAX_VALUE;
            if(n - x < d)d = n-x;
            if(x < d)d = x;
            if(m - y < d)d = m-y;
            if(y < d)d = y;
            if(d < min)min = d;
        }

        System.out.println(min >= 5 ? "NO" : "YES");
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.HashMap;

public class Main {
    private static StreamTokenizer in;
    private static PrintWriter out;
    private static BufferedReader inB;

    private static int nextInt() throws Exception{
        in.nextToken();
        return (int)in.nval;
    }

    private static String nextString() throws Exception{
        in.nextToken();
        return in.sval;
    }

    static{
        inB = new BufferedReader(new InputStreamReader(System.in));
        in = new StreamTokenizer(inB);
        out = new PrintWriter(System.out);
    }

    public static void main(String[] args)throws Exception {
        int n = nextInt(), m = nextInt(), k = nextInt();

        int min = Integer.MAX_VALUE;
        for(int i = 0; i<k; i++) {
            int x = nextInt()-1, y = nextInt()-1;
            int d = Integer.MAX_VALUE;
            if((n - 1) - x < d)d = n-1-x;
            if(x < d)d = x;
            if((m - 1) - y < d)d = m-1-y;
            if(y < d)d = y;
            if(d < min)min = d;
        }

        System.out.println(min >= 5 ? "NO" : "YES");
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Cake implements Runnable {
    private void solve() throws IOException {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        boolean wins = false;
        for (int i = 0; i < k; ++i) {
            int x = nextInt();
            int y = nextInt();
            if (x <= 5 || y <= 5 || x >= n - 4 || y >= m - 4)
                wins = true;
        }
        if (wins) writer.println("YES"); else writer.println("NO");
    }

    public static void main(String[] args) {
        new Cake().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define for1(i, n) for(int i = 1; i <= int(n); ++i)
#define ford(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define debug(x) {cerr << #x << " = " << x << endl;}
template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a){ return a * a; }

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = (int)1E9 + 7;
const ld EPS = 1E-9;
const ld PI = 3.1415926535897932384626433832795;

int n, m, k;

int main() {
    #ifdef myproject
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    #endif

    cin >> n >> m >> k;

    forn(i, k){
        int x, y;
        cin >> x >> y;
        --x, --y;

        if(x == 0 || x == n-1 || x == 1 || x == n-2){
            puts("YES");
            exit(0);
        }
        if(y == 0 || y == m-1 || y == 1 || y == m-2){
            puts("YES");
            exit(0);
        }
        if(x == 2 || x == n-3){
            puts("YES");
            exit(0);
        }
        if(y == 2 || y == m-3){
            puts("YES");
            exit(0);
        }
    }

    puts("NO");
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define for1(i, n) for(int i = 1; i <= int(n); ++i)
#define ford(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define debug(x) {cerr << #x << " = " << x << endl;}
template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a){ return a * a; }

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = (int)1E9 + 7;
const ld EPS = 1E-9;
const ld PI = 3.1415926535897932384626433832795;

int n, m, k;

int main() {
    #ifdef myproject
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    #endif

    cin >> n >> m >> k;

    forn(i, k){
        int x, y;
        cin >> x >> y;
        --x, --y;

        if(x == 0 || x == n-1 || x == 1 || x == n-2){
            puts("YES");
            exit(0);
        }
        if(y == 0 || y == m-1 || y == 1 || y == m-2){
            puts("YES");
            exit(0);
        }
    }

    puts("NO");
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define for1(i, n) for(int i = 1; i <= int(n); ++i)
#define ford(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define debug(x) {cerr << #x << " = " << x << endl;}
template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a){ return a * a; }

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = (int)1E9 + 7;
const ld EPS = 1E-9;
const ld PI = 3.1415926535897932384626433832795;

int n, m, k;

int main() {
    #ifdef myproject
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    #endif

    cin >> n >> m >> k;

    forn(i, k){
        int x, y;
        cin >> x >> y;
        --x, --y;

        if(x == 0 || x == n-1 || x == 1 || x == n-2){
            puts("YES");
            exit(0);
        }
        if(y == 0 || y == m-1 || y == 1 || y == m-2){
            puts("YES");
            exit(0);
        }
        if(x == 2 || x == n-3){
            puts("YES");
            exit(0);
        }
        if(y == 2 || y == m-3){
            puts("YES");
            exit(0);
        }
        if(x == 3 || x == n-4){
            puts("YES");
            exit(0);
        }
        if(y == 3 || y == m-4){
            puts("YES");
            exit(0);
        }
        if(x == 4 || x == n-5){
            puts("YES");
            exit(0);
        }
        if(y == 4 || y == m-5){
            puts("YES");
            exit(0);
        }
    }

    puts("NO");
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define for1(i, n) for(int i = 1; i <= int(n); ++i)
#define ford(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define debug(x) {cerr << #x << " = " << x << endl;}
template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a){ return a * a; }

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = (int)1E9 + 7;
const ld EPS = 1E-9;
const ld PI = 3.1415926535897932384626433832795;

int n, m, k;

int main() {
    #ifdef myproject
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    #endif

    cin >> n >> m >> k;

    forn(i, k){
        int x, y;
        cin >> x >> y;
        --x, --y;

        if(x == 0 || x == n-1 || x == 1 || x == n-2){
            puts("YES");
            exit(0);
        }
        if(y == 0 || y == m-1 || y == 1 || y == m-1){
            puts("YES");
            exit(0);
        }
    }

    puts("NO");
    exit(0);

    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define for1(i, n) for(int i = 1; i <= int(n); ++i)
#define ford(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define debug(x) {cerr << #x << " = " << x << endl;}
template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a){ return a * a; }

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int INF = (int)1E9 + 7;
const ld EPS = 1E-9;
const ld PI = 3.1415926535897932384626433832795;

int n, m, k;

int main() {
    #ifdef myproject
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    #endif

    cin >> n >> m >> k;

    forn(i, k){
        int x, y;
        cin >> x >> y;
        --x, --y;

        if(x == 0 || x == n-1 || x == 1 || x == n-2){
            puts("YES");
            exit(0);
        }
        if(y == 0 || y == m-1 || y == 1 || y == m-2){
            puts("YES");
            exit(0);
        }
        if(x == 2 || x == n-3){
            puts("YES");
            exit(0);
        }
        if(y == 2 || y == m-3){
            puts("YES");
            exit(0);
        }
        if(x == 3 || x == n-4){
            puts("YES");
            exit(0);
        }
        if(y == 3 || y == m-4){
            puts("YES");
            exit(0);
        }
    }

    puts("NO");
    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;

int n, m, k, vv, comp;

bool ver(int a, int b) {
    int d1 = 1000, d2 = 1000;

    d1 = min(a, min(b, min(n - a + 1, m - b + 1)));

    if(d1 > 5)
        return 0;
    return 1;
}

int main() {
    int i;
   // freopen("ttt", "r", stdin);

    cin >> n >> m >> k;

    for(i = 1; i <= k; ++i) {
        int a, b;
        cin >> a >> b;
        if(ver(a, b)) {
            cout << "YES";
            return 0;
        }
    }

    cout << "NO";

    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;

int n, m, k, vv, comp;

int calc(int el) {
    if(el == comp && !vv) {
        vv = 1;
        return 1000;
    }

    return el;
}

bool ver(int a, int b) {
    int d1, d2 = 1000;

    d1 = min(a, min(b, min(n - a + 1, m - b + 1)));
    vv = 0; comp = d1;

    d2 = min(d2, calc(a));
    d2 = min(d2, calc(b));
    d2 = min(d2, calc(n - a + 1));
    d2 = min(d2, calc(m - b + 1));

    if(d1 > 3)
        return 0;
    return 1;
}

int main() {
    int i;
   // freopen("ttt", "r", stdin);

    cin >> n >> m >> k;

    for(i = 1; i <= k; ++i) {
        int a, b;
        cin >> a >> b;
        if(ver(a, b)) {
            cout << "YES";
            return 0;
        }
    }

    cout << "NO";

    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;

int n, m, k, vv, comp;

int calc(int el) {
    if(el == comp && !vv) {
        vv = 1;
        return 1000;
    }

    return el;
}

bool ver(int a, int b) {
    int d1, d2 = 1000;

    d1 = min(a, min(b, min(n - a + 1, m - b + 1)));
    vv = 0; comp = d1;

    d2 = min(d2, calc(a));
    d2 = min(d2, calc(b));
    d2 = min(d2, calc(n - a + 1));
    d2 = min(d2, calc(m - b + 1));

    if(d1 > 2)
        return 0;
    return 1;
}

int main() {
    int i;
   // freopen("ttt", "r", stdin);

    cin >> n >> m >> k;

    for(i = 1; i <= k; ++i) {
        int a, b;
        cin >> a >> b;
        if(ver(a, b)) {
            cout << "YES";
            return 0;
        }
    }

    cout << "NO";

    return 0;
}


#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
using namespace std;

int n, m, k, vv, comp;

bool ver(int a, int b) {
    int d1 = 1000, d2 = 1000;

    d1 = min(a, min(b, min(n - a + 1, m - b + 1)));

    if(d1 > 8)
        return 0;
    return 1;
}

int main() {
    int i;
   // freopen("ttt", "r", stdin);

    cin >> n >> m >> k;

    for(i = 1; i <= k; ++i) {
        int a, b;
        cin >> a >> b;
        if(ver(a, b)) {
            cout << "YES";
            return 0;
        }
    }

    cout << "NO";

    return 0;
}