// upsolve with rainboy
import java.io.*;
import java.util.*;

public class CF1187G extends PrintWriter {
	CF1187G() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1187G o = new CF1187G(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	ArrayList[] aa_;
	int n_, m_;
	int[] pi, dd, bb;
	int[] uu, vv, uv, cost, cost_;
	int[] cc;
	void init() {
		aa_ = new ArrayList[n_];
		for (int u = 0; u < n_; u++)
			aa_[u] = new ArrayList<Integer>();
		pi = new int[n_];
		dd = new int[n_];
		bb = new int[n_];
		uu = new int[m_];
		vv = new int[m_];
		uv = new int[m_];
		cost = new int[m_];
		cost_ = new int[m_];
		cc = new int[m_ * 2];
		m_ = 0;
	}
	void link(int u, int v, int cap, int cos) {
		int h = m_++;
		uu[h] = u;
		vv[h] = v;
		uv[h] = u ^ v;
		cost[h] = cos;
		cc[h << 1 ^ 0] = cap;
		aa_[u].add(h << 1 ^ 0);
		aa_[v].add(h << 1 ^ 1);
	}
	boolean dijkstra(int s, int t) {
		Arrays.fill(pi, INF);
		pi[s] = 0;
		TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : dd[u] != dd[v] ? dd[u] - dd[v] : u - v);
		pq.add(s);
		Integer first;
		while ((first = pq.pollFirst()) != null) {
			int u = first;
			int d = dd[u] + 1;
			ArrayList<Integer> adj = aa_[u];
			for (int h_ : adj)
				if (cc[h_] > 0) {
					int h = h_ >> 1;
					int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
					int v = u ^ uv[h];
					if (pi[v] > p || pi[v] == p && dd[v] > d) {
						if (pi[v] != INF)
							pq.remove(v);
						pi[v] = p;
						dd[v] = d;
						bb[v] = h_;
						pq.add(v);
					}
				}
		}
		return pi[t] != INF;
	}
	void push(int s, int t) {
		int c = INF;
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			c = Math.min(c, cc[h_]);
		}
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_] -= c; cc[h_ ^ 1] += c;
		}
	}
	void push1(int s, int t) {
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_]--; cc[h_ ^ 1]++;
		}
	}
	int edmonds_karp(int s, int t) {
		cost_ = Arrays.copyOf(cost, m_);
		while (dijkstra(s, t)) {
			push1(s, t);
			for (int h = 0; h < m_; h++) {
				int u = uu[h], v = vv[h];
				if (pi[u] != INF && pi[v] != INF)
					cost_[h] += pi[u] - pi[v];
			}
		}
		int c = 0;
		for (int h = 0; h < m_; h++)
			c += cost[h] * cc[h << 1 ^ 1];
		return c;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int[] ii = new int[k];
		for (int h = 0; h < k; h++)
			ii[h] = sc.nextInt() - 1;
		ArrayList[] aa = new ArrayList[n];
		for (int i = 0; i < n; i++)
			aa[i] = new ArrayList<Integer>();
		for (int h = 0; h < m; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			aa[i].add(j);
			aa[j].add(i);
		}
		int t = n + k + 1;
		n_ = n * t + 1;
		m_ = k + (m * 2 * k + n) * (t - 1);
		init();
		for (int i = 0; i < n; i++) {
			ArrayList<Integer> adj = aa[i];
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s;
				for (int j : adj) {
					int v = j * t + s + 1;
					for (int x = 1; x <= k; x++)
						link(u, v, 1, c + (x * 2 - 1) * d);
				}
			}
		}
		for (int i = 0; i < n; i++)
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s, v = u + 1;
				link(u, v, k, i == 0 ? 0 : c);
			}
		for (int h = 0; h < k; h++)
			link(n_ - 1, ii[h] * t + 0, 1, 0);
		println(edmonds_karp(n_ - 1, 0 * t + t - 1));
	}
}


// upsolve with rainboy
import java.io.*;
import java.util.*;

public class CF1187G extends PrintWriter {
	CF1187G() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1187G o = new CF1187G(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	ArrayList[] aa_;
	int n_, m_;
	int[] pi, dd, bb;
	int[] uu, vv, uv, cost, cost_;
	int[] cc;
	void init() {
		aa_ = new ArrayList[n_];
		for (int u = 0; u < n_; u++)
			aa_[u] = new ArrayList<Integer>();
		pi = new int[n_];
		dd = new int[n_];
		bb = new int[n_];
		uu = new int[m_];
		vv = new int[m_];
		uv = new int[m_];
		cost = new int[m_];
		cc = new int[m_ * 2];
		m_ = 0;
	}
	void link(int u, int v, int cap, int cos) {
		int h = m_++;
		uu[h] = u;
		vv[h] = v;
		uv[h] = u ^ v;
		cost[h] = cos;
		cc[h << 1 ^ 0] = cap;
		aa_[u].add(h << 1 ^ 0);
		aa_[v].add(h << 1 ^ 1);
	}
	boolean dijkstra(int s, int t) {
		Arrays.fill(pi, INF);
		pi[s] = 0;
		TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : dd[u] != dd[v] ? dd[u] - dd[v] : u - v);
		pq.add(s);
		Integer first;
		while ((first = pq.pollFirst()) != null) {
			int u = first;
			int d = dd[u] + 1;
			ArrayList<Integer> adj = aa_[u];
			for (int h_ : adj)
				if (cc[h_] > 0) {
					int h = h_ >> 1;
					int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
					int v = u ^ uv[h];
					if (pi[v] > p || pi[v] == p && dd[v] > d) {
						if (pi[v] != INF)
							pq.remove(v);
						pi[v] = p;
						dd[v] = d;
						bb[v] = h_;
						pq.add(v);
					}
				}
		}
		return pi[t] != INF;
	}
	void push(int s, int t) {
		int c = INF;
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			c = Math.min(c, cc[h_]);
		}
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_] -= c; cc[h_ ^ 1] += c;
		}
	}
	void push1(int s, int t) {
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_]--; cc[h_ ^ 1]++;
		}
	}
	int edmonds_karp(int s, int t) {
		cost_ = Arrays.copyOf(cost, m_);
		while (dijkstra(s, t)) {
			push1(s, t);
			for (int h = 0; h < m_; h++) {
				int u = uu[h], v = vv[h];
				if (pi[u] != INF && pi[v] != INF)
					cost_[h] += pi[u] - pi[v];
			}
		}
		int c = 0;
		for (int h = 0; h < m_; h++)
			c += cost[h] * cc[h << 1 ^ 1];
		return c;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int[] ii = new int[k];
		for (int h = 0; h < k; h++)
			ii[h] = sc.nextInt() - 1;
		ArrayList[] aa = new ArrayList[n];
		for (int i = 0; i < n; i++)
			aa[i] = new ArrayList<Integer>();
		for (int h = 0; h < m; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			aa[i].add(j);
			aa[j].add(i);
		}
		int t = n + k + 1;
		n_ = n * t + 1;
		m_ = k + (m * 2 * k + n) * (t - 1);
		init();
		for (int i = 0; i < n; i++) {
			ArrayList<Integer> adj = aa[i];
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s;
				for (int j : adj) {
					int v = j * t + s + 1;
					for (int x = 1; x <= k; x++)
						link(u, v, 1, c + (x * 2 - 1) * d);
				}
			}
		}
		for (int i = 0; i < n; i++)
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s, v = u + 1;
				link(u, v, k, i == 0 ? 0 : c);
			}
		for (int h = 0; h < k; h++)
			link(n_ - 1, ii[h] * t + 0, 1, 0);
		println(edmonds_karp(n_ - 1, 0 * t + t - 1));
	}
}


// upsolve with rainboy
import java.io.*;
import java.util.*;

public class CF1187G extends PrintWriter {
	CF1187G() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1187G o = new CF1187G(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	ArrayList[] aa_;
	int n_, m_;
	int[] pi, dd, bb;
	int[] uu, vv, uv, cost;
	int[] cc;
	void init() {
		aa_ = new ArrayList[n_];
		for (int u = 0; u < n_; u++)
			aa_[u] = new ArrayList<Integer>();
		pi = new int[n_];
		dd = new int[n_];
		bb = new int[n_];
		qq = new int[nq];
		iq = new boolean[n_];
		uu = new int[m_];
		vv = new int[m_];
		uv = new int[m_];
		cost = new int[m_];
		cc = new int[m_ * 2];
		m_ = 0;
	}
	void link(int u, int v, int cap, int cos) {
		int h = m_++;
		uu[h] = u;
		vv[h] = v;
		uv[h] = u ^ v;
		cost[h] = cos;
		cc[h << 1 ^ 0] = cap;
		aa_[u].add(h << 1 ^ 0);
		aa_[v].add(h << 1 ^ 1);
	}
	int[] qq;
	int nq = 1 << 20, head, cnt;
	boolean[] iq;
	void enqueue(int v) {
		if (iq[v])
			return;
		if (head + cnt == nq) {
			if (cnt * 2 <= nq)
				System.arraycopy(qq, head, qq, 0, cnt);
			else {
				int[] qq_ = new int[nq *= 2];
				System.arraycopy(qq, head, qq_, 0, cnt);
				qq = qq_;
			}
			head = 0;
		}
		qq[head + cnt++] = v; iq[v] = true;
	}
	int dequeue() {
		int u = qq[head++]; cnt--; iq[u] = false;
		return u;
	}
	boolean spfa(int s, int t) {
		Arrays.fill(pi, INF);
		pi[s] = 0;
		head = cnt = 0;
		enqueue(s);
		while (cnt > 0) {
			int u = dequeue();
			int d = dd[u] + 1;
			ArrayList<Integer> adj = aa_[u];
			for (int h_ : adj)
				if (cc[h_] > 0) {
					int h = h_ >> 1;
					int p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);
					int v = u ^ uv[h];
					if (pi[v] > p || pi[v] == p && dd[v] > d) {
						pi[v] = p;
						dd[v] = d;
						bb[v] = h_;
						enqueue(v);
					}
				}
		}
		return pi[t] != INF;
	}
	void push(int s, int t) {
		int c = INF;
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			c = Math.min(c, cc[h_]);
		}
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_] -= c; cc[h_ ^ 1] += c;
		}
	}
	void push1(int s, int t) {
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_]--; cc[h_ ^ 1]++;
		}
	}
	int edmonds_karp(int s, int t) {
		while (spfa(s, t))
			push1(s, t);
		int c = 0;
		for (int h = 0; h < m_; h++)
			c += cost[h] * cc[h << 1 ^ 1];
		return c;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int[] ii = new int[k];
		for (int h = 0; h < k; h++)
			ii[h] = sc.nextInt() - 1;
		ArrayList[] aa = new ArrayList[n];
		for (int i = 0; i < n; i++)
			aa[i] = new ArrayList<Integer>();
		for (int h = 0; h < m; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			aa[i].add(j);
			aa[j].add(i);
		}
		int t = n + k + 1;
		n_ = n * t + 1;
		m_ = k + (m * 2 * k + n) * (t - 1);
		init();
		for (int i = 0; i < n; i++) {
			ArrayList<Integer> adj = aa[i];
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s;
				for (int j : adj) {
					int v = j * t + s + 1;
					for (int x = 1; x <= k; x++)
						link(u, v, 1, c + (x * 2 - 1) * d);
				}
			}
		}
		for (int i = 0; i < n; i++)
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s, v = u + 1;
				link(u, v, k, i == 0 ? 0 : c);
			}
		for (int h = 0; h < k; h++)
			link(n_ - 1, ii[h] * t + 0, 1, 0);
		println(edmonds_karp(n_ - 1, 0 * t + t - 1));
	}
}


// upsolve with rainboy
import java.io.*;
import java.util.*;

public class CF1187G extends PrintWriter {
	CF1187G() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1187G o = new CF1187G(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	ArrayList[] aa_;
	int n_, m_;
	int[] pi, dd, bb;
	int[] uu, vv, uv, cost;
	boolean[] iq;
	int[] cc;
	void init() {
		aa_ = new ArrayList[n_];
		for (int u = 0; u < n_; u++)
			aa_[u] = new ArrayList<Integer>();
		pi = new int[n_];
		dd = new int[n_];
		bb = new int[n_];
		iq = new boolean[n_];
		uu = new int[m_];
		vv = new int[m_];
		uv = new int[m_];
		cost = new int[m_];
		cc = new int[m_ * 2];
		m_ = 0;
	}
	void link(int u, int v, int cap, int cos) {
		int h = m_++;
		uu[h] = u;
		vv[h] = v;
		uv[h] = u ^ v;
		cost[h] = cos;
		cc[h << 1 ^ 0] = cap;
		aa_[u].add(h << 1 ^ 0);
		aa_[v].add(h << 1 ^ 1);
	}
	boolean dijkstra(int s, int t) {
		Arrays.fill(pi, INF);
		pi[s] = 0;
		TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : dd[u] != dd[v] ? dd[u] - dd[v] : u - v);
		pq.add(s); iq[s] = true;
		Integer first;
		while ((first = pq.pollFirst()) != null) {
			int u = first;
			iq[u] = false;
			int d = dd[u] + 1;
			ArrayList<Integer> adj = aa_[u];
			for (int h_ : adj)
				if (cc[h_] > 0) {
					int h = h_ >> 1;
					int p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);
					int v = u ^ uv[h];
					if (pi[v] > p || pi[v] == p && dd[v] > d) {
						if (iq[v]) {
							pq.remove(v); iq[v] = false;
						}
						pi[v] = p;
						dd[v] = d;
						bb[v] = h_;
						pq.add(v); iq[v] = true;
					}
				}
		}
		return pi[t] != INF;
	}
	void push(int s, int t) {
		int c = INF;
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			c = Math.min(c, cc[h_]);
		}
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_] -= c; cc[h_ ^ 1] += c;
		}
	}
	void push1(int s, int t) {
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_]--; cc[h_ ^ 1]++;
		}
	}
	int edmonds_karp(int s, int t) {
		while (dijkstra(s, t))
			push1(s, t);
		int c = 0;
		for (int h = 0; h < m_; h++)
			c += cost[h] * cc[h << 1 ^ 1];
		return c;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int[] ii = new int[k];
		for (int h = 0; h < k; h++)
			ii[h] = sc.nextInt() - 1;
		ArrayList[] aa = new ArrayList[n];
		for (int i = 0; i < n; i++)
			aa[i] = new ArrayList<Integer>();
		for (int h = 0; h < m; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			aa[i].add(j);
			aa[j].add(i);
		}
		int t = n + k + 1;
		n_ = n * t + 1;
		m_ = k + (m * 2 * k + n) * (t - 1);
		init();
		for (int i = 0; i < n; i++) {
			ArrayList<Integer> adj = aa[i];
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s;
				for (int j : adj) {
					int v = j * t + s + 1;
					for (int x = 1; x <= k; x++)
						link(u, v, 1, c + (x * 2 - 1) * d);
				}
			}
		}
		for (int i = 0; i < n; i++)
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s, v = u + 1;
				link(u, v, k, i == 0 ? 0 : c);
			}
		for (int h = 0; h < k; h++)
			link(n_ - 1, ii[h] * t + 0, 1, 0);
		println(edmonds_karp(n_ - 1, 0 * t + t - 1));
	}
}


// upsolve with rainboy
import java.io.*;
import java.util.*;

public class CF1187G extends PrintWriter {
	CF1187G() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1187G o = new CF1187G(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	ArrayList[] aa_;
	int n_, m_;
	int[] pi, kk, bb;
	int[] uu, vv, uv, cost, cost_;
	int[] cc;
	void init() {
		aa_ = new ArrayList[n_];
		for (int u = 0; u < n_; u++)
			aa_[u] = new ArrayList<Integer>();
		pi = new int[n_];
		kk = new int[n_];
		bb = new int[n_];
		uu = new int[m_];
		vv = new int[m_];
		uv = new int[m_];
		cost = new int[m_];
		cost_ = new int[m_];
		cc = new int[m_ * 2];
		m_ = 0;
	}
	void link(int u, int v, int cap, int cos) {
		int h = m_++;
		uu[h] = u;
		vv[h] = v;
		uv[h] = u ^ v;
		cost[h] = cos;
		cc[h << 1 ^ 0] = cap;
		aa_[u].add(h << 1 ^ 0);
		aa_[v].add(h << 1 ^ 1);
	}
	void dijkstra(int s) {
		Arrays.fill(pi, INF);
		pi[s] = 0;
		TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);
		pq.add(s);
		Integer first;
		while ((first = pq.pollFirst()) != null) {
			int u = first;
			int k = kk[u] + 1;
			ArrayList<Integer> adj = aa_[u];
			for (int h_ : adj)
				if (cc[h_] > 0) {
					int h = h_ >> 1;
					int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
					int v = u ^ uv[h];
					if (pi[v] > p || pi[v] == p && kk[v] > k) {
						if (pi[v] < INF)
							pq.remove(v);
						pi[v] = p;
						kk[v] = k;
						bb[v] = h_;
						pq.add(v);
					}
				}
		}
	}
	void push(int s, int t) {
		int c = INF;
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			c = Math.min(c, cc[h_]);
		}
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_] -= c; cc[h_ ^ 1] += c;
		}
	}
	void push1(int s, int t) {
		for (int u = t, h_, h; u != s; u ^= uv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_]--; cc[h_ ^ 1]++;
		}
	}
	int edmonds_karp(int s, int t) {
		System.arraycopy(cost, 0, cost_, 0, m_);
		while (true) {
			dijkstra(s);
			if (pi[t] == INF)
				break;
			push1(s, t);
			for (int h = 0; h < m_; h++) {
				int u = uu[h], v = vv[h];
				if (pi[u] != INF && pi[v] != INF)
					cost_[h] += pi[u] - pi[v];
			}
		}
		int c = 0;
		for (int h = 0; h < m_; h++)
			c += cost[h] * cc[h << 1 ^ 1];
		return c;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int[] ii = new int[k];
		for (int h = 0; h < k; h++)
			ii[h] = sc.nextInt() - 1;
		ArrayList[] aa = new ArrayList[n];
		for (int i = 0; i < n; i++)
			aa[i] = new ArrayList<Integer>();
		for (int h = 0; h < m; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			aa[i].add(j);
			aa[j].add(i);
		}
		int t = n + k + 1;
		n_ = n * t + 1;
		m_ = k + (m * 2 * k + n) * (t - 1);
		init();
		for (int i = 0; i < n; i++) {
			ArrayList<Integer> adj = aa[i];
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s;
				for (int j : adj) {
					int v = j * t + s + 1;
					for (int x = 1; x <= k; x++)
						link(u, v, 1, c + (x * 2 - 1) * d);
				}
			}
		}
		for (int i = 0; i < n; i++)
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s, v = u + 1;
				link(u, v, k, i == 0 ? 0 : c);
			}
		for (int h = 0; h < k; h++)
			link(n_ - 1, ii[h] * t + 0, 1, 0);
		println(edmonds_karp(n_ - 1, 0 * t + t - 1));
	}
}


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

public class GG {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int K = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();
        MinCostMaxFlowSolver solver = new EdmondsKarp();
        int[] people = new int[K];
        for(int i = 0; i < K; i++) people[i] = scanner.nextInt()-1;
        Node src = solver.addNode();
        Node snk = solver.addNode();
        int amt = 150;
        Node[][] timeNodes = new Node[N][amt];
        for(int i = 0; i < N; i++) {
            for(int j = 1; j < amt; j++) {
                timeNodes[i][j] = solver.addNode();
                if (j > 1) solver.link(timeNodes[i][j-1], timeNodes[i][j], Integer.MAX_VALUE, 0);
            }
        }
        for(int i = 0; i < K; i++) {
            solver.link(src, timeNodes[people[i]][1], 1, 0);
        }
        for(int i = 1; i < amt; i++) {
            for(int j = 0; j < K; j++) {
                solver.link(timeNodes[0][i], snk, 1, C*i-C);
            }
        }
        for(int i =0; i < M; i++) {
            int a = scanner.nextInt()-1;
            int b = scanner.nextInt()-1;
            for(int j = 1; j < amt-1; j++) {
                int prev = 0;
                for(int k = 1; k <= K; k++) {
                    solver.link(timeNodes[a][j], timeNodes[b][j + 1], 1, D*k*k- prev);
                    solver.link(timeNodes[b][j], timeNodes[a][j + 1], 1, D*k*k - prev);
                    prev = D * k * k;
                }
            }
        }
        long[] ret = solver.getMinCostMaxFlow(src, snk);
        out.println(ret[1]);
        out.flush();
    }

    public static class Node {
        // thou shall not create nodes except through addNode()
        private Node() { }

        List<Edge> edges = new ArrayList<Edge>();
        int index;          // index in nodes array

    }

    public static class Edge
    {
        boolean forward; // true: edge is in original graph
        Node from, to;   // nodes connected
        long flow;        // current flow
        final long capacity;
        Edge dual;      // reference to this edge's dual
        long cost;      // only used for MinCost.
        protected Edge(Node s, Node d, long c, boolean f)
        {
            forward = f;
            from = s;
            to = d;
            capacity = c;
        }
        long remaining() { return capacity - flow; }
        void addFlow(long amount) {
            flow += amount;
            dual.flow -= amount;
        }
    }

    public static abstract class MaxFlowSolver {
        List<Node> nodes = new ArrayList<Node>();

        public void link(Node n1, Node n2, long capacity) {
            link(n1, n2, capacity, 1);
        }

        public void link(Node n1, Node n2, long capacity, long cost) {
            Edge e12 = new Edge(n1, n2, capacity, true);
            Edge e21 = new Edge(n2, n1, 0, false);
            e12.dual = e21;
            e21.dual = e12;
            n1.edges.add(e12);
            n2.edges.add(e21);
            e12.cost = cost;
            e21.cost = -cost;
        }
        void link(int n1, int n2, long capacity) {
            link(nodes.get(n1), nodes.get(n2), capacity);
        }
        protected MaxFlowSolver(int n) {
            for (int i = 0; i < n; i++)
                addNode();
        }
        protected MaxFlowSolver() {
            this(0);
        }

        public abstract long getMaxFlow(Node src, Node snk);
        public Node addNode() {
            Node n = new Node();
            n.index = nodes.size();
            nodes.add(n);
            return n;
        }
    }
    static abstract class MinCostMaxFlowSolver extends MaxFlowSolver {
        // returns [maxflow, mincost]
        abstract long [] getMinCostMaxFlow(Node src, Node snk);
        // unavoidable boiler plate
        MinCostMaxFlowSolver ()      { this(0); }
        MinCostMaxFlowSolver (int n) { super(n); }
    }

    static class EdmondsKarp extends MinCostMaxFlowSolver
    {
        EdmondsKarp ()      { this(0); }
        EdmondsKarp (int n) { super(n); }
        long minCost;

        @Override
        public long [] getMinCostMaxFlow(Node src, Node snk) {
            long maxflow = getMaxFlow(src, snk);
            return new long [] { maxflow, minCost };
        }
        static final long INF = Long.MAX_VALUE/4;

        @Override
        public long getMaxFlow(Node src, Node snk) {
            final int n = nodes.size();
            final int source = src.index;
            final int sink = snk.index;
            long flow = 0;
            long cost = 0;
            long[] potential = new long[n]; // allows Dijkstra to work with negative edge weights
            while (true) {
                Edge[] parent = new Edge[n]; // used to store an augmenting path
                long[] dist = new long[n]; // minimal cost to vertex
                Arrays.fill(dist, INF);
                dist[source] = 0;
                PriorityQueue<Item> que = new PriorityQueue<Item>();
                que.add(new Item(0, source));
                while (!que.isEmpty()) {
                    Item item = que.poll();
                    if (item.dist != dist[item.v])
                        continue;

                    for (Edge e : nodes.get(item.v).edges) {
                        long temp = dist[item.v] + e.cost + potential[item.v] - potential[e.to.index];
                        if (e.capacity > e.flow && dist[e.to.index] > temp) {
                            dist[e.to.index] = temp;
                            parent[e.to.index] = e;
                            que.add(new Item(temp, e.to.index));
                        }
                    }
                }
                if (parent[sink] == null)
                    break;
                for (int i = 0; i < n; i++)
                    if (parent[i] != null)
                        potential[i] += dist[i];
                long augFlow = Long.MAX_VALUE;
                for (int i = sink; i != source; i = parent[i].from.index)
                    augFlow = Math.min(augFlow, parent[i].capacity - parent[i].flow);
                for (int i = sink; i != source; i = parent[i].from.index) {
                    Edge e = parent[i];
                    e.addFlow(augFlow);
                    cost += augFlow * e.cost;
                }
                flow += augFlow;
            }

            minCost = cost;
            return flow;
        }

        static class Item implements Comparable<Item> {
            long dist;
            int v;

            public Item(long dist, int v) {
                this.dist = dist;
                this.v = v;
            }

            public int compareTo(Item that) {
                return Long.compare(this.dist, that.dist);
            }
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


// upsolve with rainboy
import java.io.*;
import java.util.*;

public class CF1187G extends PrintWriter {
	CF1187G() { super(System.out); }
	static class Scanner {
		Scanner(InputStream in) { this.in = in; } InputStream in;
		int k, l; byte[] bb = new byte[1 << 15];
		byte getc() {
			if (k >= l) {
				k = 0;
				try { l = in.read(bb); } catch (IOException e) { l = 0; }
				if (l <= 0) return -1;
			}
			return bb[k++];
		}
		int nextInt() {
			byte c = 0; while (c <= 32) c = getc();
			int a = 0;
			while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
			return a;
		}
	}
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1187G o = new CF1187G(); o.main(); o.flush();
	}

	static final int INF = 0x3f3f3f3f;
	ArrayList[] aa_;
	int n_, m_;
	int[] pi, kk, bb;
	int[] uu, vv, cost, cost_;
	int[] cc;
	void init() {
		aa_ = new ArrayList[n_];
		for (int u = 0; u < n_; u++)
			aa_[u] = new ArrayList<Integer>();
		pi = new int[n_];
		kk = new int[n_];
		bb = new int[n_];
		uu = new int[m_];
		vv = new int[m_];
		cost = new int[m_];
		cost_ = new int[m_];
		cc = new int[m_ * 2];
		m_ = 0;
	}
	void link(int u, int v, int cap, int cos) {
		int h = m_++;
		uu[h] = u;
		vv[h] = v;
		cost[h] = cos;
		cc[h << 1 ^ 0] = cap;
		aa_[u].add(h << 1 ^ 0);
		aa_[v].add(h << 1 ^ 1);
	}
	void dijkstra(int s) {
		Arrays.fill(pi, INF);
		pi[s] = 0;
		TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);
		pq.add(s);
		Integer first;
		while ((first = pq.pollFirst()) != null) {
			int u = first;
			int k = kk[u] + 1;
			ArrayList<Integer> adj = aa_[u];
			for (int h_ : adj)
				if (cc[h_] > 0) {
					int h = h_ >> 1;
					int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
					int v = u ^ uu[h] ^ vv[h];
					if (pi[v] > p || pi[v] == p && kk[v] > k) {
						if (pi[v] < INF)
							pq.remove(v);
						pi[v] = p;
						kk[v] = k;
						bb[v] = h_;
						pq.add(v);
					}
				}
		}
	}
	void push(int s, int t) {
		int c = INF;
		for (int u = t, h_, h; u != s; u ^= uu[h] ^ vv[h]) {
			h = (h_ = bb[u]) >> 1;
			c = Math.min(c, cc[h_]);
		}
		for (int u = t, h_, h; u != s; u ^= uu[h] ^ vv[h]) {
			h = (h_ = bb[u]) >> 1;
			cc[h_] -= c; cc[h_ ^ 1] += c;
		}
	}
	int edmonds_karp(int s, int t) {
		System.arraycopy(cost, 0, cost_, 0, m_);
		while (true) {
			dijkstra(s);
			if (pi[t] == INF)
				break;
			push(s, t);
			for (int h = 0; h < m_; h++) {
				int u = uu[h], v = vv[h];
				if (pi[u] != INF && pi[v] != INF)
					cost_[h] += pi[u] - pi[v];
			}
		}
		int c = 0;
		for (int h = 0; h < m_; h++)
			c += cost[h] * cc[h << 1 ^ 1];
		return c;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int[] ii = new int[k];
		for (int h = 0; h < k; h++)
			ii[h] = sc.nextInt() - 1;
		ArrayList[] aa = new ArrayList[n];
		for (int i = 0; i < n; i++)
			aa[i] = new ArrayList<Integer>();
		for (int h = 0; h < m; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			aa[i].add(j);
			aa[j].add(i);
		}
		int t = n + k + 1;
		n_ = n * t + 1;
		m_ = k + (m * 2 * k + n) * (t - 1);
		init();
		for (int i = 0; i < n; i++) {
			ArrayList<Integer> adj = aa[i];
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s;
				for (int j : adj) {
					int v = j * t + s + 1;
					for (int x = 1; x <= k; x++)
						link(u, v, 1, c + (x * 2 - 1) * d);
				}
			}
		}
		for (int i = 0; i < n; i++)
			for (int s = 0; s < t - 1; s++) {
				int u = i * t + s, v = u + 1;
				link(u, v, k, i == 0 ? 0 : c);
			}
		for (int h = 0; h < k; h++)
			link(n_ - 1, ii[h] * t + 0, 1, 0);
		println(edmonds_karp(n_ - 1, 0 * t + t - 1));
	}
}


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

public class Main{

	public static void main(String[] Args) throws Exception {
	     Scanner sc = new Scanner(new FileReader("input.txt"));
	     int n,m,k;
	     Integer lx,ly;
	     boolean d[][];
	     n = sc.nextInt(); m = sc.nextInt(); k = sc.nextInt();
	     d = new boolean [n+1][m+1];
	     for(int i=0;i<=n;++i)
	      for(int j=0;j<=m;++j)
	       d[i][j]=false;

	     Queue< pair > q = new LinkedList< pair >();
	     lx = ly = -1;
	     for(int i=0;i<k;++i){
	     	int x,y; x = sc.nextInt(); y = sc.nextInt();
	     	q.add(new pair(x,y)); lx = x; ly = y;
	     	d[x][y]=true;
	     }

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

	     while(!q.isEmpty()){
	     	 pair tp = q.remove();
	     	 int x = tp.x; int y = tp.y;
	     	 for(int i=0;i<4;++i){
	     	 	 int nx = x+dx[i]; int ny = y+dy[i];
	     	 	 if(nx<1 || nx>n || ny<1 || ny>m || d[nx][ny] ) continue;
	     	     d[nx][ny]=true;
	     	     q.add(new pair(nx,ny));
	     	     lx = nx; ly = ny;
	     	 }
	     }
	     FileWriter fw = new FileWriter("output.txt");
	     fw.write(lx.toString()); fw.write(" "); fw.write(ly.toString());;
	     fw.flush();

	}
}
class pair {

  public int x,y;
  public pair(int _x,int _y){ x = _x; y = _y; }

}


import java.util.LinkedList;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.ArrayList;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Collection;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Queue;
import java.io.IOException;
import java.io.FileOutputStream;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author nasko
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("input.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("output.txt");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {

    public void solve(int testNumber, InputReader in, PrintWriter out) {

        int N = in.nextInt();
        int M = in.nextInt();
        int K = in.nextInt();
        int[][] dist = new int[N+1][M+1];
        for(int[] ini : dist) Arrays.fill(ini,1 << 30);
        int best = 0;
        ArrayList<Integer> result = new ArrayList<Integer>();
        Queue<Integer> q = new LinkedList<Integer>();
        for(int k = 0; k < K; ++k) {
            int x = in.nextInt();
            int y = in.nextInt();
            dist[x][y] = 0;
            q.offer(x);
            q.offer(y);

        }

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

        while(!q.isEmpty()) {

            int a = q.poll();
            int b = q.poll();
            for(int r = 0; r < 4; ++r) {
                int x = a + dx[r];
                int y = b + dy[r];
                if(x >= 1 && x <= N && y >=1 && y <= M && dist[x][y] > dist[a][b] + 1) {
                    dist[x][y] = dist[a][b] + 1;

                    q.offer(x);
                    q.offer(y);
                }
            }
        }
        for(int i = 1; i <= N; ++i)
            for(int j = 1; j <= M; ++j) best = Math.max(best,dist[i][j]);
        for(int a = 1; a <= N; ++a)
            for(int b = 1; b <= M; ++b) if(dist[a][b] == best) {
                result.add(a);
                result.add(b);
            }

        if(result.size() > 0) {
            out.print(result.get(0) + " " + result.get(1));
        }

        out.println();

    }

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

}


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

public class SolutionC{
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(new File("input.txt"));
		PrintWriter output = new PrintWriter("output.txt");
		int N = sc.nextInt();
		int M = sc.nextInt();
		int K = sc.nextInt();
		int[] x = new int[K];
		int[] y = new int[K];
		for(int i = 0 ; i < K ; i++){
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		int max = -1, max_x = -1, max_y = -1;
		for(int i = 1 ; i <= N ; i++){
			for(int j = 1 ; j <= M ; j++){
				int min = Integer.MAX_VALUE;
				for(int k = 0 ; k < K ; k++){
					min = Math.min(min, Math.abs(x[k] - i) + Math.abs(y[k] - j));
				}
				if(min > max){
					max = min;
					max_x = i;
					max_y = j;
				}
			}
		}
		output.println(max_x + " " + max_y);
		output.flush();
	}
}


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

public class PracticeProblem
{
    /*
     * This FastReader code is taken from GeeksForGeeks.com
     * https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
     *
     * The article was written by Rishabh Mahrsee
     */
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() throws FileNotFoundException
        {
            br = new BufferedReader(new FileReader(new File("input.txt")));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static FastReader in;
    public static PrintWriter out;
    public static final int INF = Integer.MAX_VALUE;
    public static int n, m;

    public static final int[] dr = {-1, 0, 0, +1};
    public static final int[] dc = {0, -1, +1, 0};

    public static void main(String[] args) throws FileNotFoundException
    {
        in = new FastReader();
        out = new PrintWriter(new File("output.txt"));
        solve();
        out.close();
    }

    private static void solve()
    {
        n = in.nextInt();
        m = in.nextInt();
        int k = in.nextInt();

        int[][] timeToBurn = new int[n][m];
        for (int i = 0; i < n; i++)
            Arrays.fill(timeToBurn[i], INF);

        for (int i = 0; i < k; i++)
        {
            int r = in.nextInt() - 1;
            int c = in.nextInt() - 1;
            for (int j = 0; j < n; j++)
            {
                for (int l = 0; l < m; l++)
                {
                    timeToBurn[j][l] = min(timeToBurn[j][l], abs(r - j) + abs(c - l));
                }
            }
        }
        int max = -1;
        Point p = null;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (timeToBurn[i][j] > max)
                {
                    max = timeToBurn[i][j];
                    p = new Point(i, j);
                }
            }
        }

        out.println((p.x + 1) + " " + (p.y + 1));
    }

}


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

public class Main implements Runnable {

	public void solve() throws IOException {
		int N = nextInt();
                int M = nextInt();

                int B = nextInt();
                int[][] burn = new int[B][2];
                for(int i = 0; i < B; i++){
                        burn[i][0] = nextInt();
                        burn[i][1] = nextInt();
                }

                int ansx = -1;
                int ansy = -1;
                int ans = -1;

                for(int i = 1; i <= N; i++){
                        for(int j = 1; j <= M; j++){
                                int burnAt = Integer.MAX_VALUE;
                                for(int k = 0; k < B; k++){
                                        int now = distance(i, j, burn[k][0], burn[k][1]);
                                        burnAt = Math.min(burnAt, now);
                                }
                                //System.out.println(burnAt + " " + i + " " + j);
                                if(burnAt >= ans){

                                        ans = burnAt;
                                        ansx = i;
                                        ansy = j;

                                }
                        }
                }

                out.println(ansx + " " + ansy);
	}

        private int distance(int x, int y, int xx, int yy){
                //withour sqrt
                return Math.abs(xx - x) + Math.abs(yy - y);
        }

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

	public void run() {
		try {
			//in = new BufferedReader(new InputStreamReader(System.in));
			in = new BufferedReader(new FileReader(new File("input.txt")));
                        out = new PrintWriter(new FileWriter(new File("output.txt")));
                        tok = null;
			solve();
			in.close();
                        out.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

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

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

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

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

        PrintWriter out;
	BufferedReader in;
	StringTokenizer tok;
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;

public class FireAgain {

	public static void main(String[] args) throws IOException {
		BufferedReader readData = new BufferedReader(new FileReader("input.txt"));
		PrintWriter writer = new PrintWriter(new File("output.txt"));
		String line = readData.readLine();
		String[] temp = line.split(" ");
		int n = Integer.valueOf(temp[0]);
		int m = Integer.valueOf(temp[1]);
		int x = 0, y = 0;
		line = readData.readLine();
		int k = Integer.valueOf(line);
		boolean[][] visited = new boolean[n + 1][m + 1];
		Queue<Integer> qX = new LinkedList<Integer>();
		Queue<Integer> qY = new LinkedList<Integer>();
		line = readData.readLine();
		String[] temp2 = line.split(" ");
		for (int i = 0; i < temp2.length - 1; i+=2) {
			x = Integer.valueOf(temp2[i]);
			y = Integer.valueOf(temp2[i + 1]);
			visited[x][y] = true;
			qX.add(x);
			qY.add(y);
		}

		while (!qX.isEmpty()) {
			x = qX.poll();
			y = qY.poll();
			if (x >= 2 && !visited[x - 1][y]) {
				visited[x - 1][y] = true;
				qX.add(x - 1);
				qY.add(y);
			}
			if (x + 1 <= n && !visited[x + 1][y]) {
				visited[x + 1][y] = true;
				qX.add(x + 1);
				qY.add(y);
			}
			if (y >= 2 && !visited[x][y - 1]) {
				visited[x][y - 1] = true;
				qX.add(x);
				qY.add(y - 1);
			}
			if (y + 1 <= m && !visited[x][y + 1]) {
				visited[x][y + 1] = true;
				qX.add(x);
				qY.add(y + 1);
			}
		}
		writer.write(x + " ");
		writer.write(y + " ");
		writer.close();
	}

}


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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));
		PrintWriter pw = new PrintWriter(new File("output.txt"));

		StringTokenizer st;

		st = new StringTokenizer(in.readLine());

		int n = Integer.parseInt(st.nextToken()),
			m = Integer.parseInt(st.nextToken()),
			k = Integer.parseInt(in.readLine());

		int[][] A = new int[n][m];

		st = new StringTokenizer(in.readLine());
		for (int i = 0 ; i < k ; i++) {
			int x1 = Integer.parseInt(st.nextToken()) - 1,
				y1 = Integer.parseInt(st.nextToken()) - 1;

			A[x1][y1] = -10000000;

			for (int j = 0 ; j < n ; j++) {
				for (int g = 0 ; g < m ; g++) {
					if (A[j][g] == 0 || (A[j][g] > (Math.abs(y1 - g) + Math.abs(x1 - j)))) {
						A[j][g] = (Math.abs(y1 - g) + Math.abs(x1 - j));
					}
				}
			}
		}

		int f = 0, h = 0;

		for (int i = 0 ; i < n ; i++) {
			for (int j = 0 ; j < m ; j++) {
				if (A[i][j] != -10000000) {
					f = i;
					h = j;
				}
			}
		}

		for (int i = 0 ; i < n ; i++) {
			for (int j = 0 ; j < m ; j++) {
				if (A[i][j] > A[f][h] && A[i][j] != -10000000) {
					f = i;
					h = j;
				}
			}
		}
	//	for (int i = 0 ; i < n ; i++) for (int j = 0 ; j < m ; j++) System.out.println(A[i][j]);
		pw.println((f + 1) + " " + (h + 1));
		pw.close();
	}
}


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

public class C35C_BFS_Fire {
    public static boolean[][] burning;
    public static LinkedList<int[]> LitTrees; //which is best to use
    public static int N, M;
    public static int[] lastTree;
    public static void main(String[] args) throws IOException {
        // InputStreamReader stream = new InputStreamReader(System.in);
        // BufferedReader input = new BufferedReader(stream);

        BufferedReader input = new BufferedReader(new FileReader("input.txt"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));

        StringTokenizer dataR = new StringTokenizer(input.readLine());
        N = Integer.parseInt(dataR.nextToken());
        M = Integer.parseInt(dataR.nextToken());
        burning = new boolean[N+1][M+1];

        StringTokenizer dataR1 = new StringTokenizer(input.readLine());
        int K = Integer.parseInt(dataR1.nextToken());

        StringTokenizer dataR2 = new StringTokenizer(input.readLine());
        LitTrees = new LinkedList<int[]>();
        for (int j = 0; j < K; j++){
            int x = Integer.parseInt(dataR2.nextToken());
            int y = Integer.parseInt(dataR2.nextToken());
            int[] coord = {x, y};
            LitTrees.add(coord);
            burning[x][y] = true;
        }

        spread();

        out.println(lastTree[0] + " " + lastTree[1]);
        out.close();

    }

    public static void spread(){
        while(!LitTrees.isEmpty()){
            int[] studying = LitTrees.remove(); //is iterator faster
            LinkedList<int[]> ll = new LinkedList<int[]>();

            if(studying[0]-1 >= 1) ll.add(new int[]{studying[0]-1, studying[1]});
            if(studying[1]-1 >= 1) ll.add(new int[]{studying[0], studying[1]-1});
            if(studying[1]+1 < M+1) ll.add(new int[]{studying[0], studying[1]+1});
            if(studying[0]+1 < N+1) ll.add(new int[]{studying[0]+1, studying[1]});

            while(!ll.isEmpty()) {
                int[] focus = ll.remove();
                if(!burning[focus[0]][focus[1]]) {
                    LitTrees.add(focus);
                    burning[focus[0]][focus[1]] = true;
                }
            }

            lastTree = studying;
        }
    }

}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
	static int n, m, k;
	static int inf = (int) 1e9;
	static class Pair {
		int x, y;
		Pair(int a, int b) {
			x = a; y = b;
		}
	}
	static int[] dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
	static boolean valid(int x, int y) {
		return x >= 0 && x < n && y >= 0 && y < m;
	}
	static int[][] bfs(int[] xs, int[] ys) {
		int[][] dist = new int[n][m];
		for(int i = 0; i < n; i++)
			Arrays.fill(dist[i], inf);
		Queue<Pair> q = new LinkedList<>();
		for(int i = 0; i < k; i++) {
			dist[xs[i]][ys[i]] = 0;
			q.add(new Pair(xs[i], ys[i]));
		}

		while(!q.isEmpty()) {
			Pair p = q.remove();
			for(int d = 0; d < 4; d++) {
				int nx = p.x + dx[d], ny = p.y + dy[d];
				if(valid(nx, ny) && dist[nx][ny] == inf) {
					dist[nx][ny] = dist[p.x][p.y] + 1;
					q.add(new Pair(nx, ny));
				}
			}
		}

		return dist;
	}

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner();
		int n = in.nextInt() ;
		int m = in.nextInt();
		int k = in.nextInt();
		int x[] = new int[k] ;
		int y[] = new int[k] ;
		int trees [][] = new int [n][m] ;

		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				trees[i][j]=Integer.MAX_VALUE ;

		for (int i = 0; i < k; i++)
		{
			x[i]=in.nextInt()-1;
			y[i]=in.nextInt()-1;
			trees[x[i]][y[i]]=0 ;
		}

		int dis = Integer.MIN_VALUE ; ;
		int xp=0; ;
		int yp=0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < m; j++)
				if(trees[i][j] != 0)
					for (int j2 = 0; j2 < k; j2++)
						trees[i][j]=Math.min(trees[i][j], Math.abs(i-x[j2])+Math.abs(j-y[j2]));

		for (int i = 0; i <n; i++)
			for (int j = 0; j < m; j++)
				if(trees[i][j] > dis)
				{
					dis=trees[i][j];
					xp=i+1;
					yp=j+1;
				}
		PrintWriter out = new PrintWriter("output.txt");
		out.printf("%d %d\n", xp ,yp);
		out.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;
		Scanner() throws FileNotFoundException {
			br = new BufferedReader(new FileReader("input.txt"));
		}

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

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


import java.awt.Point;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class sdffsdf {

	public static void main(String[] args) {
		try{
			File file = new File("input.txt");
			Scanner sc = new Scanner(file);
			String s = sc.nextLine();
			String[] seperatedd = s.split(" ");
			int x = Integer.parseInt(seperatedd[0]);
			int y = Integer.parseInt(seperatedd[1]);
			int[][] grid = new int[x][y];
			for(int i = 0; i < x; i++)
			{
				for(int j = 0; j < y; j++)
				{
					grid[i][j] = 0;
				}
			}
			s = sc.nextLine();
			int z = Integer.parseInt(s);
			LinkedList<Point> BFS = new LinkedList<Point>();
			s = sc.nextLine();
			String[] seperated = s.split(" ");
			for(int i = 0; i < seperated.length; i = i + 2)
			{
				Point temp = new Point();
				temp.x = Integer.parseInt(seperated[i])-1;
				temp.y = Integer.parseInt(seperated[i+1])-1;
				grid[temp.x][temp.y] = 1;
				BFS.addLast(temp);
			}
			while(!BFS.isEmpty())
			{
				Point temp = new Point();
				temp = BFS.removeFirst();
			 	int	k = temp.x;
			 	int l = temp.y;

				if(!(l+1 >= y || grid[k][l+1] == 1))
				{
					Point temp1 = new Point();
					temp1.x = k;
					temp1.y = l+1;
					grid[temp1.x][temp1.y] = 1;
					BFS.addLast(temp1);
				}
				if(!(k+1 >= x || grid[k+1][l] == 1))
				{
					Point temp1 = new Point();
					temp1.x = k+1;
					temp1.y = l;
					grid[temp1.x][temp1.y] = 1;
					BFS.addLast(temp1);
				}

				if(!(l-1 < 0 || grid[k][l-1] == 1))
				{
					Point temp1 = new Point();
					temp1.x = k;
					temp1.y = l-1;
					grid[temp1.x][temp1.y] = 1;
					BFS.addLast(temp1);
				}
				if(!(k-1 < 0 || grid[k-1][l] == 1))
				{
					Point temp1 = new Point();
					temp1.x = k-1;
					temp1.y = l;
					grid[temp1.x][temp1.y] = 1;
					BFS.addLast(temp1);
				}
				if(BFS.isEmpty())
				{
			try {
						File fil = new File("output.txt");
						PrintWriter out = new PrintWriter(fil);
						int v1 = (int)temp.getX() + 1;
						int v2 = (int)temp.getY() + 1;
						out.println(v1 + " " + v2);
				        out.close();
					}
					catch (Exception e) {}
				}
			}
		}
		catch (Exception e) {
			System.out.println("nbvnb");
		}

	}

}


import java.awt.Point;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintStream;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.HashSet;

public class FireAgain {

	Point[] coordinate;
	Queue<Point> q = new LinkedList<>();
	// HashSet<Point> vis = new HashSet<>();
	boolean[][] vis;
	PrintStream out;
	int x, y;

	boolean distance(Point word1, Point word2) {

		if (Math.abs(word1.x - word2.x) == 1 && Math.abs(word1.y - word2.y) == 1)
			return false;

		if (Math.abs(word1.x - word2.x) == 1 && word1.y == word2.y)
			return true;

		if (word1.x == word2.x && Math.abs(word1.y - word2.y) == 1)
			return true;

		return false;
	}

	void bfs(Point s) {

		while (!q.isEmpty()) {
			s = q.poll();

			Point p = new Point();
			p.x = s.x - 1;
			p.y = s.y;

			if (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {
				if (!vis[p.x][p.y]) {
					vis[p.x][p.y] = true;
					q.add(p);

				}
			}

			p = new Point();
			p.x = s.x + 1;
			p.y = s.y;

			if (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {
				if (!vis[p.x][p.y]) {
					vis[p.x][p.y] = true;
					q.add(p);

				}
			}

			p = new Point();
			p.x = s.x;
			p.y = s.y - 1;

			if (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {
				if (!vis[p.x][p.y]) {
					vis[p.x][p.y] = true;
					q.add(p);

				}
			}

			p = new Point () ;
			p.x = s.x ;
			p.y = s.y + 1;

			if (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {
				if (!vis[p.x][p.y]) {
					vis[p.x][p.y] = true ;
					q.add(p);

				}
			}

			if (q.size() == 0)
				out.print(s.x + " " + s.y);
		}

	}

	public static void main(String[] args) throws FileNotFoundException {
		// TODO Auto-generated method stub

		FireAgain F = new FireAgain();
		 Scanner in = new Scanner (new FileReader("input.txt"));
		 F.out = new PrintStream(new File("output.txt"));

		F.x = in.nextInt();
		F.y = in.nextInt();

		int l = 0;
		F.vis = new boolean[F.x + 1][F.y + 1];

		int k = in.nextInt();

		for (int i = 0; i < k; i++) {
			Point P = new Point(in.nextInt(), in.nextInt());
			F.vis[P.x][P.y] = true; // add in set
			F.q.add(P);
		}

		F.bfs(F.q.peek());

	}

}


import java.io.*;
import java.math.*;
import java.security.KeyStore.Entry;
import java.util.*;

			public class QA {

				static long MOD = 1000000007;
				static boolean b[], b1[], check;
				static ArrayList<Integer>[] amp, pa;
				static ArrayList<Pair>[] amp1;
				static ArrayList<Pair>[][] damp;
				static int left[],right[],end[],sum[],dist[],cnt[],start[],color[],parent[],prime[],size[];
				static int ans = 0,k;
				static int p = 0;
				static FasterScanner sc = new FasterScanner(System.in);
				//static Queue<Integer> q = new LinkedList<>();
				static BufferedWriter log;
				static HashSet<Pair> hs;
				static HashMap<Pair,Integer> hm;
				static PriorityQueue<Integer> pri[];
				static ArrayList<Integer>[] level;
				static Stack<Integer> st;
				static boolean boo[][];
				static Pair prr[];
				static long parent1[],parent2[],size1[],size2[],arr1[],SUM[],lev[], fibo[];
				static int arr[], ver[][];
				static private PrintWriter out = new PrintWriter(System.out);
				public static void main(String[] args) throws Exception {
			    	new Thread(null, new Runnable() {
						public void run() {
							try {
				soln();
						} catch (Exception e) {
								System.out.println(e);
							}
						}
					}, "1", 1 << 26).start();

				}
				private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;
				private static void tr(Object... o) {
					if (!oj)
						System.out.println(Arrays.deepToString(o));
				}
				static int dp[][];
				static int N,K,T,A,B;
				static long time;
				static int cost[][];
				static boolean b11[];
				static HashMap<Integer,Integer> h = new HashMap<>();
				static HashSet<Pair> chec;
				static long ans1;		static long ans2;
				static int BLOCK, MAX = 1000001;
				static double pi = Math.PI;
				static int Arr[], Brr[], pow[],  M;
				static long fact[] = new long[100000+1];
				static HashMap<Integer,Long> hm1;
				static HashSet<Integer> hs1[], hs2[];
				static String[] str2;
				static char[] ch1, ch2;
				static int[] s,f,D;
				static int tf,ts;
				static int see[][] = new int[2050][2050];
				static boolean bee[][] = new boolean[2050][2050];
				static Queue<Pair> q = new LinkedList<>();
				//static PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
				public static void soln() throws IOException {
					//System.setIn(new FileInputStream("input.txt"));
					//System.setOut(new PrintStream("output.txt"));
					FasterScanner sc = new FasterScanner(new FileInputStream("input.txt"));//("C:\\Users\\Admin\\Desktop\\QAL2.txt"));
					//PrintWriter log1 = new PrintWriter("C:\\Users\\Admin\\Desktop\\input01");
					PrintWriter log = new PrintWriter("output.txt");//("C:\\Users\\Admin\\Desktop\\output00");
					//log = new BufferedWriter(new OutputStreamWriter(System.out));
					int n = sc.nextInt() , m = sc.nextInt();
					int k = sc.nextInt();
					for(int i = 1; i <= n ; i++) for(int j  =1;j<=m;j++) see[i][j]= 100000000;
					for(int i = 0; i < k; i++){
						int x = sc.nextInt(), y = sc.nextInt();
						bee[x][y] = true;
						see[x][y] = 0;
						q.add(new Pair(x,y));
					}
					while(!q.isEmpty()){
						//System.out.println(q);
						int x = q.peek().u, y = q.poll().v;
						if(x>1){
							see[x-1][y] = min(see[x][y]+1,see[x-1][y]);
							if(!bee[x-1][y]) q.add(new Pair(x-1,y));
							bee[x-1][y] = true;
						}
						if(x<n){
							see[x+1][y] = min(see[x][y]+1,see[x+1][y]);
							if(!bee[x+1][y]) q.add(new Pair(x+1,y));
							bee[x+1][y] = true;
						}
						if(y>1){
							see[x][y-1] = min(see[x][y]+1,see[x][y-1]);
							if(!bee[x][y-1]) q.add(new Pair(x,y-1));
							bee[x][y-1] = true;
						}
						if(y<m){
							see[x][y+1] = min(see[x][y]+1,see[x][y+1]);
							if(!bee[x][y+1]) q.add(new Pair(x,y+1));
							bee[x][y+1] = true;
						}
					}
					int ans = -1;
					Pair temp = null;
					for(int i = 1;i<=n;i++){
						for(int j = 1;j<=m;j++){
							if(see[i][j]>ans) {
								ans = see[i][j];
								temp = new Pair(i,j);
							}
						}
					}
					log.write(temp.u+" "+temp.v);
					log.close();
				}
				static int min(int a, int b){
					if(a>b) return b;
					return a;
				}
				private static double dfs(int cur,int prev){
					double r=0,n=0;
					for(int i : amp[cur]){
						if(i!=prev){
							r+=(1+dfs(i,cur));
							n++;
						}
					}
					if(n!=0){
						r=r/n;
					}
					return r;
				}
				static double fa1 = 0;
				static int fa = -1;
				static long nCr1(int n, int r){
					if(n<r) return 0;
					return (((fact[n] * modInverse(fact[n-r], MOD))%MOD)*modInverse(fact[r], MOD))%MOD;
				}
				static class Node{
					Node arr[] = new Node[2];
					int cnt[] = new int[2];
				}
				public static class Trie{
					Node root;
					public Trie(){
						root = new Node();
					}
					public void insert(String x){
						Node n = root;
						for(int i = 0;i < x.length() ;i++){
							int a1 = x.charAt(i)-'0';
							if(n.arr[a1]!=null){
								n.cnt[a1]++;
								n = n.arr[a1];
								continue;
							}
							n.arr[a1] = new Node();
							n.cnt[a1]++;
							n = n.arr[a1];
						}
					}
					public void delete(String x){
						Node n = root;
						for(int i = 0;i < x.length() ;i++){
							int a1 = x.charAt(i)-'0';
							if(n.cnt[a1]==1){
								n.arr[a1] = null;
								return;
							}
							else {
								n.cnt[a1]--;
								n = n.arr[a1];
							}
						}
					}
					public long get(String x){
						Node n = root;
						long ans = 0;
						for(int i = 0;i < x.length() ;i++){
							int a1 = '1' - x.charAt(i);
							if(n.arr[a1]!=null){
								ans += Math.pow(2, 30-i);
								n = n.arr[a1];
							}
							else n = n.arr[1-a1];
						//	System.out.println(ans);
						}
						return ans;
					}
				}
				public static class FenwickTree {

				    int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates

				    public FenwickTree(int size) {
				        array = new int[size + 1];
				    }
				    public int rsq(int ind) {
				        assert ind > 0;
				        int sum = 0;
				        while (ind > 0) {
				            sum += array[ind];
				            //Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number
				            ind -= ind & (-ind);
				        }
				        return sum;
				    }
				    public int rsq(int a, int b) {
				        assert b >= a && a > 0 && b > 0;
				        return rsq(b) - rsq(a - 1);
				    }
				    public void update(int ind, int value) {
				        assert ind > 0;
				        while (ind < array.length) {
				            array[ind] += value;
				            //Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number
				            ind += ind & (-ind);
				        }
				    }

				    public int size() {
				        return array.length - 1;
				    }
				}
				static double power(double x, long y)
				{
				    if (y == 0)
				        return 1;
				    double p = power(x, y/2);
				    p = (p * p);

				    return (y%2 == 0)? p : (x * p);
				}
				static int Dfs(int x, int val){
					b[x] = true;
					for(int p:hs2[x]){
						if(!b[p]){
							if(!hs1[x].contains(p)) val++;
							val += Dfs(p,0);
						}
					}
					return val;
				}
				static long nCr(int n, int r){
					if(n<r) return 0;
					else return (((fact[n]*modInverse(fact[r], MOD))%MOD)*modInverse(fact[n-r], MOD))%MOD;
				}
				static void dfs1(int x, int p){
					arr1[x] += lev[x];
					for(int v:amp[x]){
						if(v!=p){
							dfs1(v,x);
						}
					}
				}

				static void bfs(int x){

				}
				public static void seive(int n){
					b = new boolean[(n+1)];
					Arrays.fill(b, true);
					b[1] = true;
					for(int i = 2;i*i<=n;i++){
						if(b[i]){
							for(int p = 2*i;p<=n;p+=i){
								b[p] = false;
							}
						}
					}
					/*for(int i = 2;i<=n;i++){
						if(b[i]) prime[i] = i;
					}*/
				}

				static class Graph{
					int vertex;
					int weight;
					Graph(int v, int w){
						vertex = v;
						weight = w;
					}
				}
				static class Pair implements Comparable<Pair> {
					int u;
					int v;
					int ans;
					public Pair(){
						u = 0;
						v = 0;
					}
					public Pair(int u, int v) {
						this.u = u;
						this.v = v;
					}
					public int hashCode() {
						return Objects.hash();
					}
					public boolean equals(Object o) {
						Pair other = (Pair) o;
						return ((u == other.u && v == other.v && ans == other.ans));
					}

					public int compareTo(Pair other) {
						//return Double.compare(ans, other.ans);
						return Long.compare(u, other.u);
					}

					public String toString() {
						return "[u=" + u + ", v=" + v + "]";
					}
				}

				public static void buildGraph(int n){
					for(int i =0;i<n;i++){
						int x = sc.nextInt()-1, y = sc.nextInt()-1;
						amp[x].add(y);
						amp[y].add(x);
					}
				}

				public static int getParent(long x){
					while(parent[(int) x]!=x){
						parent[ (int) x] = parent[(int) parent[ (int) x]];
						x = parent[ (int) x];
					}
					return (int) x;
				}
				static long min(long a, long b, long c){
					if(a<b && a<c) return a;
					if(b<c) return b;
					return c;
				}
				/*

				static class Pair3{
					int x, y ,z;
					Pair3(int x, int y, int z){
						this.x = x;
						this.y = y;
						this.z = z;
					}
				}*/
				 static void KMPSearch(String pat, String txt)
				    {
				        int M = pat.length();
				        int N = txt.length();

				        // create lps[] that will hold the longest
				        // prefix suffix values for pattern
				        int lps[] = new int[M];
				        int j = 0;  // index for pat[]

				        // Preprocess the pattern (calculate lps[]
				        // array)
				        computeLPSArray(pat,M,lps);

				        int i = 0;  // index for txt[]
				        while (i < N)
				        {
				            if (pat.charAt(j) == txt.charAt(i))
				            {
				                j++;
				                i++;
				            }
				            if (j == M)
				            {
				               // parent.add((i-j));
				                j = lps[j-1];
				            }

				            // mismatch after j matches
				            else if (i < N && pat.charAt(j) != txt.charAt(i))
				            {
				                // Do not match lps[0..lps[j-1]] characters,
				                // they will match anyway
				                if (j != 0)
				                    j = lps[j-1];
				                else
				                    i = i+1;
				            }
				        }
				    }
				 static void computeLPSArray(String pat, int M, int lps[])
				    {
				        // length of the previous longest prefix suffix
				        int len = 0;
				        int i = 1;
				        lps[0] = 0;  // lps[0] is always 0

				        // the loop calculates lps[i] for i = 1 to M-1
				        while (i < M)
				        {
				            if (pat.charAt(i) == pat.charAt(len))
				            {
				                len++;
				                lps[i] = len;
				                i++;
				            }
				            else  // (pat[i] != pat[len])
				            {
				                // This is tricky. Consider the example.
				                // AAACAAAA and i = 7. The idea is similar
				                // to search step.
				                if (len != 0)
				                {
				                    len = lps[len-1];

				                    // Also, note that we do not increment
				                    // i here
				                }
				                else  // if (len == 0)
				                {
				                    lps[i] = len;
				                    i++;
				                }
				            }
				        }
				    }
				private static void permutation(String prefix, String str) {
				    int n = str.length();
				    if (n == 0); //hs.add(prefix);
				    else {
				        for (int i = 0; i < n; i++)
				            permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
				    }
				}

				public static void buildTree(int n){
					int arr[] = sc.nextIntArray(n);
					for(int i = 0;i<n;i++){
						int x = arr[i]-1;
						amp[i+1].add(x);
						amp[x].add(i+1);
					}
				}

				static class SegmentTree {
					boolean st[];
					boolean lazy[];

					SegmentTree(int n) {
						int size = 4 * n;
						st = new boolean[size];
						Arrays.fill(st, true);
						lazy = new boolean[size];
						Arrays.fill(lazy, true);
						//build(0, n - 1, 1);
					}

					/*long[] build(int ss, int se, int si) {
						if (ss == se) {
							st[si][0] = 1;
							st[si][1] = 1;
							st[si][2] = 1;
							return st[si];
						}
						int mid = (ss + se) / 2;
						long a1[] = build(ss, mid, si * 2), a2[] = build(mid + 1, se,
								si * 2 + 1);
						long ans[] = new long[3];
						if (arr[mid] < arr[mid + 1]) {
							ans[1] = Math.max(a2[1], Math.max(a1[1], a1[2] + a2[0]));
							if (a1[1] == (mid - ss + 1))
								ans[0] = ans[1];
							else
								ans[0] = a1[0];
							if (a2[2] == (se - mid))
								ans[2] = ans[1];
							else
								ans[2] = a2[2];
						} else {
							ans[1] = Math.max(a1[1], a2[1]);
							ans[0] = a1[0];
							ans[2] = a2[2];
						}
						st[si] = ans;
						return st[si];
					}*/

					void update(int si, int ss, int se, int idx, long x) {
						if (ss == se) {
							//arr[idx] += val;
							st[si]=false;
						}
						else {
							int mid = (ss + se) / 2;
							if(ss <= idx && idx <= mid)
					        {
					             update(2*si, ss, mid, idx, x);
					        }
					        else
					        { update(2*si+1, mid+1, se, idx, x);
					        }
							st[si] = st[2*si]|st[2*si+1];
						}
					}
					/*boolean get(int qs, int qe, int ss, int se, int si){
						if(qs>se || qe<ss) return 0;
						if (qs <= ss && qe >= se) {
							return st[si];
						}
						int mid = (ss+se)/2;
						return get(qs, qe, ss, mid, si * 2)+get(qs, qe, mid + 1, se, si * 2 + 1);
					}*/
					void updateRange(int node, int start, int end, int l, int r, boolean val)
					{
					    if(!lazy[node])
					    {
					        // This node needs to be updated
					        st[node] = lazy[node];    // Update it
					        if(start != end)
					        {
					            lazy[node*2] = lazy[node];                  // Mark child as lazy
					            lazy[node*2+1] = lazy[node];                // Mark child as lazy
					        }
					        lazy[node] = true;                                  // Reset it
					    }
					    if(start > end || start > r || end < l)              // Current segment is not within range [l, r]
					        return;
					    if(start >= l && end <= r)
					    {
					        // Segment is fully within range
					        st[node] =  val;
					        if(start != end)
					        {
					            // Not leaf node
					            lazy[node*2] = val;
					            lazy[node*2+1] = val;
					        }
					        return;
					    }
					    int mid = (start + end) / 2;
					    updateRange(node*2, start, mid, l, r, val);        // Updating left child
					    updateRange(node*2 + 1, mid + 1, end, l, r, val);   // Updating right child
					    st[node] = st[node*2] | st[node*2+1];        // Updating root with max value
					}

					boolean queryRange(int node, int start, int end, int l, int r)
					{
					    if(start > end || start > r || end < l)
					        return false;         // Out of range
					    if(!lazy[node])
					    {
					        // This node needs to be updated
					        st[node] = lazy[node];            // Update it
					        if(start != end)
					        {
					            lazy[node*2] = lazy[node];         // Mark child as lazy
					            lazy[node*2+1] = lazy[node];    // Mark child as lazy
					        }
					        lazy[node] = true;                 // Reset it
					    }
					    if(start >= l && end <= r)             // Current segment is totally within range [l, r]
					        return  st[node];
					    int mid = (start + end) / 2;
					    boolean p1 = queryRange(node*2, start, mid, l, r);         // Query left child
					    boolean b = queryRange(node*2 + 1, mid + 1, end, l, r); // Query right child
					    return (p1 | b);
					}
					void print() {
						for (int i = 0; i < st.length; i++) {
							System.out.print(st[i]+" ");
						}
						System.out.println();
					}
				}
				static int convert(int x){
					int cnt = 0;
					String str = Integer.toBinaryString(x);
					//System.out.println(str);
					for(int i = 0;i<str.length();i++){
						if(str.charAt(i)=='1'){
							cnt++;
						}
					}
					int ans = (int) Math.pow(3, 6-cnt);
					return ans;
				}
				static class Node2{
					Node2 left = null;
					Node2 right = null;
					Node2 parent = null;
					int data;
				}
				static boolean check(char ch[][], int i, int j){
					if(ch[i][j]=='O') return false;
					char c = ch[i][j];
					ch[i][j] = 'X';
					if(c=='X'){
					if(i>=4){
						int x = 0;
						int l = 0;
						for(x = 0;x<=4;x++){
							if(ch[i-x][j]!='X'){ if(ch[i-x][j]!='.') break;else l++;}
						}
						if(x==5 && l<=1) return true;
						l = 0;
						if(j>=4){
							for(x = 0;x<=4;x++){
								if(ch[i-x][j-x]!='X'){ if(ch[i-x][j-x]!='.') break; else l++;}
							}
							if(x==5 && l<=1) return true;
							 l =0;
							for(x = 0;x<=4;x++){
								if(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}
							}
							if(x==5 && l<=1) return true;
						}
						if(j<=5){
							l = 0;
							for(x = 0;x<=4;x++){
								if(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}
							}
							if(x==5 && l<=1) return true;
							l = 0;
							for(x = 0;x<=4;x++){
								if(ch[i-x][j+x]!='X'){ if(ch[i-x][j+x]!='.') break; else l++;}
							}
							if(x==5 && l<=1) return true;
						}
					}
					if(i<=5){
						int x = 0;
						int l = 0;
						for(x = 0;x<=4;x++){
							if(ch[i+x][j]!='X'){ if(ch[i+x][j]!='.') break; else l++;}
						}
						if(x==5 && l<=1) return true;
						l = 0;
						if(j>=4){
							for(x = 0;x<=4;x++){
								if(ch[i+x][j-x]!='X'){ if(ch[i+x][j-x]!='.') break; else l++;}
							}
							if(x==5 && l<=1) return true;
							 l =0;
							for(x = 0;x<=4;x++){
								if(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}
							}
							if(x==5 && l<=1) return true;
						}
						if(j<=5){
							l = 0;
							for(x = 0;x<=4;x++){
								if(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}
							}
							if(x==5 && l<=1) return true;
							l = 0;
							for(x = 0;x<=4;x++){
								if(ch[i+x][j+x]!='X'){ if(ch[i+x][j+x]!='.') break; else l++;}
							}
							if(x==5 && l<=1) return true;
						}
					}
					}
					else{
						if(i>=4){
							int x = 0;
							int l = 0;
							for(x = 0;x<=4;x++){
								if(ch[i-x][j]!='X'){ if(ch[i-x][j]!='.') break;else l++;}
							}
							if(x==5 && l<=0) return true;
							l = 0;
							if(j>=4){
								for(x = 0;x<=4;x++){
									if(ch[i-x][j-x]!='X'){ if(ch[i-x][j-x]!='.') break; else l++;}
								}
								if(x==5 && l<=0) return true;
								 l =0;
								for(x = 0;x<=4;x++){
									if(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}
								}
								if(x==5 && l<=0) return true;
							}
							if(j<=5){
								l = 0;
								for(x = 0;x<=4;x++){
									if(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}
								}
								if(x==5 && l<=0) return true;
								l = 0;
								for(x = 0;x<=4;x++){
									if(ch[i-x][j+x]!='X'){ if(ch[i-x][j+x]!='.') break; else l++;}
								}
								if(x==5 && l<=0) return true;
							}
						}
						if(i<=5){
							int x = 0;
							int l = 0;
							for(x = 0;x<=4;x++){
								if(ch[i+x][j]!='X'){ if(ch[i+x][j]!='.') break; else l++;}
							}
							if(x==5 && l<=0) return true;
							l = 0;
							if(j>=4){
								for(x = 0;x<=4;x++){
									if(ch[i+x][j-x]!='X'){ if(ch[i+x][j-x]!='.') break; else l++;}
								}
								if(x==5 && l<=0) return true;
								 l =0;
								for(x = 0;x<=4;x++){
									if(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}
								}
								if(x==5 && l<=0) return true;
							}
							if(j<=5){
								l = 0;
								for(x = 0;x<=4;x++){
									if(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}
								}
								if(x==5 && l<=0) return true;
								l = 0;
								for(x = 0;x<=4;x++){
									if(ch[i+x][j+x]!='X'){ if(ch[i+x][j+x]!='.') break; else l++;}
								}
								if(x==5 && l<=0) return true;
							}
						}
					}
					ch[i][j] = c;

					return false;
				}
				static class BinarySearchTree{
					Node2 root = null;
					int height = 0;
					int max = 0;
					int cnt = 1;
					ArrayList<Integer> parent = new ArrayList<>();
					HashMap<Integer, Integer> hm = new HashMap<>();
					public void insert(int x){
						Node2 n = new Node2();
						n.data = x;
						if(root==null){
							root = n;
						}
						else{
							Node2 temp = root,temb = null;
							while(temp!=null){
								temb = temp;
								if(x>temp.data) temp = temp.right;
								else temp = temp.left;
							}
							if(x>temb.data) temb.right = n;
							else temb.left = n;
							n.parent = temb;
							parent.add(temb.data);
						}
					}
					public Node2 getSomething(int x, int y, Node2 n){
						if(n.data==x || n.data==y) return n;
						else if(n.data>x && n.data<y) return n;
						else if(n.data<x && n.data<y) return getSomething(x,y,n.right);
						else return getSomething(x,y,n.left);
					}
					public Node2 search(int x,Node2 n){
						if(x==n.data){
							max = Math.max(max, n.data);
							return n;
						}
						if(x>n.data){
							max = Math.max(max, n.data);
							return search(x,n.right);
						}
						else{
							max = Math.max(max, n.data);
							return search(x,n.left);
						}
					}
					public int getHeight(Node2 n){
						if(n==null) return 0;
						height = 1+ Math.max(getHeight(n.left), getHeight(n.right));
						return height;
					}
				}
				static long findDiff(long[] arr, long[] brr, int m){
					int i = 0, j = 0;
					long fa = 1000000000000L;
					while(i<m && j<m){
						long x = arr[i]-brr[j];
						if(x>=0){
							if(x<fa) fa = x;
							j++;
						}
						else{
							if((-x)<fa) fa = -x;
							i++;
						}
					}
					return fa;
				}
				public static long max(long x, long y, long z){
					if(x>=y && x>=z) return x;
					if(y>=x && y>=z) return y;
					return z;
				}

				static long modInverse(long a, long mOD2){
				            return  power(a, mOD2-2, mOD2);
				}
				static long power(long x, long y, long m)
				{
				    if (y == 0)
				        return 1;
				    long p = power(x, y/2, m) % m;
				    p = (p * p) % m;

				    return (y%2 == 0)? p : (x * p) % m;
				}
				static long d,x,y;
				public static void extendedEuclidian(long a, long b){
					if(b == 0) {
				        d = a;
				        x = 1;
				        y = 0;
				    }
				    else {
				        extendedEuclidian(b, a%b);
				        int temp = (int) x;
				        x = y;
				        y = temp - (a/b)*y;
				    }
				}

				public static long gcd(long n, long m){
					if(m!=0) return gcd(m,n%m);
					else return n;
				}

				static BufferedReader reader;
			    static StringTokenizer tokenizer;
			    static PrintWriter writer;

			    static class FasterScanner {

					private final InputStream stream;
					private final byte[] buf = new byte[8192];
					private int curChar, snumChars;
					private SpaceCharFilter filter;

					public FasterScanner(InputStream stream) {
						this.stream = stream;
					}

					public int snext() {
						if (snumChars == -1)
							throw new InputMismatchException();
						if (curChar >= snumChars) {
							curChar = 0;
							try {
								snumChars = stream.read(buf);
							} catch (IOException e) {
								throw new InputMismatchException();
							}
							if (snumChars <= 0)
								return -1;
						}
						return buf[curChar++];
					}

					public int nextInt() {
						int c = snext();
						while (isSpaceChar(c)) {
							c = snext();
						}
						int sgn = 1;
						if (c == '-') {
							sgn = -1;
							c = snext();
						}
						int res = 0;
						do {
							if (c < '0' || c > '9')
								throw new InputMismatchException();
							res *= 10;
							res += c - '0';
							c = snext();
						} while (!isSpaceChar(c));
						return res * sgn;
					}

					public long nextLong() {
						int c = snext();
						while (isSpaceChar(c)) {
							c = snext();
						}
						int sgn = 1;
						if (c == '-') {
							sgn = -1;
							c = snext();
						}
						long res = 0;
						do {
							if (c < '0' || c > '9')
								throw new InputMismatchException();
							res *= 10;
							res += c - '0';
							c = snext();
						} while (!isSpaceChar(c));
						return res * sgn;
					}

					public int[] nextIntArray(int n) {
						int a[] = new int[n];
						for (int i = 0; i < n; i++) {
							a[i] = nextInt();
						}
						return a;
					}

					public long[] nextLongArray(int n) {
						long a[] = new long[n];
						for (int i = 0; i < n; i++) {
							a[i] = nextLong();
						}
						return a;
					}

					public String readString() {
						int c = snext();
						while (isSpaceChar(c)) {
							c = snext();
						}
						StringBuilder res = new StringBuilder();
						do {
							res.appendCodePoint(c);
							c = snext();
						} while (!isSpaceChar(c));
						return res.toString();
					}

					public String nextLine() {
						int c = snext();
						while (isSpaceChar(c))
							c = snext();
						StringBuilder res = new StringBuilder();
						do {
							res.appendCodePoint(c);
							c = snext();
						} while (!isEndOfLine(c));
						return res.toString();
					}

					public boolean isSpaceChar(int c) {
						if (filter != null)
							return filter.isSpaceChar(c);
						return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
					}

					private boolean isEndOfLine(int c) {
						return c == '\n' || c == '\r' || c == -1;
					}

					public interface SpaceCharFilter {
						public boolean isSpaceChar(int ch);
					}
				}
			}


import javax.annotation.processing.SupportedSourceVersion;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(new FileReader("input.txt")); // new InputReader(inputStream);
        PrintWriter out = new PrintWriter("output.txt"); //new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }

    private static class TaskB {

        static final long max = 1000000000000000000L;
        static final double eps = 0.0000001;
        static final long mod = 1000000007;
        static int N, M, K;
        static long X, Y;
        static boolean F[][][];
        static int D[][];

        void solve(InputReader in, PrintWriter out) throws IOException {

            N = in.nextInt();
            M = in.nextInt();
            K = in.nextInt();

            F = new boolean[K][N][M];
            D = new int[N][M];

            for (int i = 0; i < N; i++)
                for (int j = 0; j < M; j++)
                    D[i][j] = Integer.MAX_VALUE;

            List<Pair> list = new ArrayList<>();

            for (int i = 0; i < K; i++) {
                list.add(new Pair(in.nextInt() - 1, in.nextInt() - 1));
            }

            for (int i = 0; i < N; i++)
                for (int j = 0; j < M; j++)
                    for (int k = 0; k < K; k++)
                        D[i][j] = Math.min(D[i][j], Math.abs(list.get(k).X - i) + Math.abs(list.get(k).Y - j));

            int res = Integer.MIN_VALUE;
            for (int j = 0; j < N; j++)
                for (int k = 0; k < M; k++)
                    if (D[j][k] > res) {
                        X = j + 1;
                        Y = k + 1;
                        res = D[j][k];
                    }

            out.println(X + " " + Y);

        }

        class Pair {
            int X, Y;

            Pair(int X, int Y) {
                this.X = X;
                this.Y = Y;
            }
        }

        long gcd(long A, long B) {
            if (B == 0) return A;
            return gcd(B, A % B);
        }

        boolean isPrime(long n) {
            if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
                return false;
            for (long i = 5, j = 2; i * i <= n; i += j, j = 6 - j)
                if (n % i == 0)
                    return false;
            return true;
        }

        boolean isEqual(double A, double B) {
            return Math.abs(A - B) < eps;
        }

        double dist(double X1, double Y1, double X2, double Y2) {
            return Math.sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2));
        }

        boolean nextPer(int[] data) {
            int i = data.length - 1;
            while (i > 0 && data[i] < data[i - 1]) {
                i--;
            }
            if (i == 0) {
                return false;
            }
            int j = data.length - 1;
            while (data[j] < data[i - 1]) {
                j--;
            }
            int temp = data[i - 1];
            data[i - 1] = data[j];
            data[j] = temp;
            Arrays.sort(data, i, data.length);
            return true;
        }

        long pow(long A, long B, long MOD) {
            if (B == 0) {
                return 1;
            }
            if (B == 1) {
                return A;
            }
            long val = pow(A, B / 2, MOD);
            if (B % 2 == 0) {
                return val * val % MOD;
            } else {
                return val * (val * A % MOD) % MOD;
            }
        }
    }

    private static class InputReader {
        StringTokenizer st;
        BufferedReader br;

        public InputReader(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public InputReader(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            return st.nextToken();
        }

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

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

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

        public boolean ready() {
            try {
                return br.ready();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}


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

public class C {
	public static void main(String[] args) throws Exception {
		final int fuck = 2001;

		Scanner in = new Scanner(new File("input.txt"));
		PrintWriter out = new PrintWriter(new File("output.txt"));
		int n = in.nextInt(), m = in.nextInt();
		int[] D = new int[ fuck*fuck ], Q = new int[ fuck*(fuck + 1) ],
			dx = new int[] { 1, -1, 0, 0},
			dy = new int[] { 0, 0, -1, 1};
		Arrays.fill(D, -1);
		int H = -1, T = 0;

		int k = in.nextInt(), ans = 0;
		for(int i = 0; i < k; ++i) {
			int x = in.nextInt(), y = in.nextInt();
			D[x * fuck + y] = 0;

			++H; H %= Q.length;
			ans = Q[H] = x * fuck + y;
		}

		while(H >= T) {
			int idx = Q[T++]; T %= Q.length;
			int x = idx / fuck, y = idx % fuck;
			for(int i = 0; i < 4; ++i) {
				int wtf = (dx[i] + x) * fuck + (dy[i] + y);
				if(dx[i] + x <= n && dx[i] + x >= 1 && dy[i] + y <= m && dy[i] + y >= 1 && D[wtf] == -1) {
					D[wtf] = D[idx] + 1;
					++H; H %= Q.length;
					Q[H] = wtf;

					if(D[wtf] >= D[ans])
						ans = wtf;
				}
			}
		}

		out.println((ans / fuck) + " " + (ans % fuck));
		out.close();
		in.close();
	}
}


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

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

public class C35
{

	public static int mod = 1000000007;
	public static long INF = (1L << 60);

	static int n,m;
	static class Pair
	{
		int x,y;
		Pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}
		@Override
		public int hashCode()
		{
			final int prime = 31;
			int result = 1;
			result = prime * result + x;
			result = prime * result + y;
			return result;
		}
		@Override
		public boolean equals(Object obj)
		{
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Pair other = (Pair) obj;
			if (x != other.x)
				return false;
			if (y != other.y)
				return false;
			return true;
		}
	}
	static boolean[][] burned;
	static int[] dx={-1,0,1,0};
	static int[] dy={0,-1,0,1};
	static boolean isvalid(int x,int y)
	{
		return x>=0&&x<n&&y>=0&&y<m;
	}
	public static void main(String[] args) throws IOException
	{
		Scanner in = new Scanner("input.txt");
		PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
		n=in.nextInt();
		m=in.nextInt();
		burned=new boolean[n][m];
		int k=in.nextInt();
		Set<Pair> set=new HashSet<Pair>();
		Pair prev=null;
		for(int i=0;i<k;i++)
		{
			int x=in.nextInt();
			int y=in.nextInt();
			burned[x-1][y-1]=true;
			set.add(prev=new Pair(x-1, y-1));
		}
		while(!set.isEmpty())
		{
			Set<Pair> tempset=new HashSet<>();
		for(Pair p : set)
		{
			int x=p.x;
			int y=p.y;
			prev=p;
			for(int i=0;i<4;i++)
			{
				if(isvalid(x+dx[i], y+dy[i])&&!burned[x+dx[i]][y+dy[i]])
				{
					tempset.add(new Pair(x+dx[i], y+dy[i]));
					burned[x+dx[i]][y+dy[i]]=true;
				}
			}
		}
		set=tempset;
		}
		out.printf("%d %d\n",(prev.x+1),(prev.y+1));
		out.close();

	}

	public static long pow(long x, long n)
	{
		long res = 1;
		for (long p = x; n > 0; n >>= 1, p = (p * p))
		{
			if ((n & 1) != 0)
			{
				res = (res * p);
			}
		}
		return res;
	}

	public static long pow(long x, long n, long mod)
	{
		long res = 1;
		for (long p = x; n > 0; n >>= 1, p = (p * p) % mod)
		{
			if ((n & 1) != 0)
			{
				res = (res * p % mod);
			}
		}
		return res;
	}

	public static long gcd(long n1, long n2)
	{
		long r;
		while (n2 != 0)
		{
			r = n1 % n2;
			n1 = n2;
			n2 = r;
		}
		return n1;
	}

	public static long lcm(long n1, long n2)
	{
		long answer = (n1 * n2) / (gcd(n1, n2));
		return answer;
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public Scanner(String s) throws FileNotFoundException{	br = new BufferedReader(new FileReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {return br.readLine();}

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

		public boolean ready() throws IOException {return br.ready();}
	}
}


//package c;
import java.util.*;
import java.io.*;

public class Main {

	int n,m;
	int d[][];
	Queue<int[]> q = new LinkedList<int[]>();
	int cur[];

	public void run() throws Exception{
		Scanner in = new Scanner(new File("input.txt"));
		PrintWriter out = new PrintWriter(new File("output.txt"));
		n = in.nextInt();
		m = in.nextInt();
		int k = in.nextInt();
		d = new int[n][m];
		for(int i=0;i<n;i++) Arrays.fill(d[i], Integer.MAX_VALUE/2);
		for(int i=0;i<k;i++){
			int x = in.nextInt()-1;
			int y = in.nextInt()-1;
			d[x][y] = 0;
			q.add(new int[]{x,y});
		}

		while(q.size() > 0){
			cur = q.poll();
			int x = cur[0];
			int y = cur[1];
			add(x, y+1);
			add(x+1, y);
			add(x-1, y);
			add(x, y-1);
		}
		int max = 0;
		int x = 0;
		int y = 0;
		for(int i=0;i<n;i++)
			for(int j=0;j<m;j++)
				if (max < d[i][j]){
					max = d[i][j];
					x = i;
					y = j;
				}
		out.println((x+1) + " " + (y+1));
		out.close();
	}

	private void add(int x, int y){
		if (x < 0 || y < 0) return;
		if (x >=n || y >=m) return;
		if (d[x][y] > d[cur[0]][cur[1]] + 1){
			d[x][y] = d[cur[0]][cur[1]] + 1;
			q.add(new int[]{x,y});
		}
	}

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

}


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

public class Solution {

    BufferedReader in;
    StringTokenizer st;
    PrintWriter out;

    int n, m, k;
    int[] x, y;

    char[] qx = new char[4000000], qy = new char[4000000];
    int b, e;

    char[][] d;

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

    void bfs() {
        b = e = 0;
        for (int i = 0; i < d.length; i++) {
            Arrays.fill(d[i], (char)(1 << 14));
        }
        for (int i = 0; i < k; ++i) {
            qx[e] = (char) x[i];
            qy[e++] = (char) y[i];
            d[x[i]][y[i]] = 0;
        }
        for (; b < e; ++b) {
            int x = qx[b];
            int y = qy[b];
            for (int i = 0; i < 4; ++i) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m)
                    if (d[nx][ny] > d[x][y] + 1) {
                        d[nx][ny] = (char) (d[x][y] + 1);
                        qx[e] = (char) nx;
                        qy[e++] = (char) ny;
                    }
            }
        }
    }

    void solve() throws IOException {
        n = ni();
        m = ni();
        k = ni();
        x = new int[k];
        y = new int[k];
        for (int i = 0; i < k; ++i) {
            x[i] = ni() - 1;
            y[i] = ni() - 1;
        }
        d = new char[n][m];
        bfs();
        int x = -1, y = -1, last = -1;
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                if (d[i][j] > last) {
                    last = d[i][j];
                    x = i;
                    y = j;
                }
        ++x;
        ++y;
        out.println(x + " " + y);
    }

    public Solution() throws IOException {
        Locale.setDefault(Locale.US);
        in = new BufferedReader(new FileReader("input.txt"));
        out = new PrintWriter("output.txt");
        solve();
        in.close();
        out.close();
    }

    String nline() throws IOException {
        return in.readLine();
    }

    String ns() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(nline());
        }
        return st.nextToken();
    }

    int ni() throws IOException {
        return Integer.valueOf(ns());
    }

    long nl() throws IOException {
        return Long.valueOf(ns());
    }

    double nd() throws IOException {
        return Double.valueOf(ns());
    }

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


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintStream;
import java.util.Scanner;

public class P35C {
    int n, m;
    int [][]fire;
    public P35C() throws FileNotFoundException {
        Scanner in = new Scanner(new FileReader("input.txt"));
        n = in.nextInt();
        m = in.nextInt();
        int k = in.nextInt();
        fire = new int[k][2];
        for (int i = 0; i < k; i++){
            fire[i][0] = in.nextInt();
            fire[i][1] = in.nextInt();
        }
        in.close();

        int []last = new int[2];
        int lastBurn = -1;
        for (int i = 1; i <= n; i++){
            for (int j = 1; j <= m; j++){
                int burn = Integer.MAX_VALUE;
                for (int l = 0; l < k; l++){
                    int burnAux = dist(i, j, fire[l][0], fire[l][1]);
                    burn = Math.min(burn, burnAux);
                }
                if(burn >= lastBurn){
                    lastBurn = burn;
                    last[0] = i;
                    last[1] = j;

            }
            }
        }

        PrintStream out = new java.io.PrintStream( "output.txt" );
        out.print(last[0] + " " + last[1]);
        out.close();
    }

     int dist(int x1, int y1, int x2, int y2){
         return Math.abs(x2 - x1) + Math.abs(y2 - y1);
     }

    public static void main (String []args) throws FileNotFoundException{
        new P35C();
    }
}


/**
 * Created by IntelliJ IDEA.
 * User: Taras_Brzezinsky
 * Date: 9/16/11
 * Time: 1:27 PM
 * To change this template use File | Settings | File Templates.
 */

import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Queue;
import java.util.StringTokenizer;

public class TaskC extends Thread {
    public TaskC() {
        try {
            this.input = new BufferedReader(new FileReader("input.txt"));
            this.output = new PrintWriter("output.txt");
            this.setPriority(Thread.MAX_PRIORITY);
        } catch (Throwable e) {
            System.exit(666);
        }
    }

    private void solve() throws Throwable {
        int n = nextInt();
        int m = nextInt();
        int k = nextInt();
        Queue<Integer> qX = new ArrayDeque<Integer>();
        Queue<Integer> qY = new ArrayDeque<Integer>();
        boolean [][]was = new boolean[n][m];
        for (int i = 0; i < k; ++i) {
            int x = nextInt() - 1, y = nextInt() - 1;
            qX.add(x);
            qY.add(y);
            was[x][y] = true;
        }
        int lastX = -1, lastY = -1;
        while (!qX.isEmpty()) {
            lastX = qX.poll();
            lastY = qY.poll();
            for (int i = 0; i < dx.length; ++i) {
                int nextX = lastX + dx[i], nextY = lastY + dy[i];
                if (nextX < n && nextY < m && nextX >= 0 && nextY >= 0 && !was[nextX][nextY]) {
                    qX.add(nextX);
                    qY.add(nextY);
                    was[nextX][nextY] = true;
                }
            }
        }
        ++lastX;
        ++lastY;
        output.println(lastX + " " + lastY);

    }

    public void run() {
        try {
            solve();
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.flush();
            output.close();
        }
    }

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

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

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

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

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }
    static final int PRIME = 3119;
    static final int[]dx = {1, -1, 0, 0}, dy = {0, 0, -1, 1};
    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens = null;
}