#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
struct Coordinate {
	int x, y;
};

int main() {
	std::cin.sync_with_stdio(false);
	int h, w, n; std::cin >> h >> w >> n;
	std::vector<std::vector<Coordinate>> floor(h, std::vector<Coordinate>(w));
	for (auto& line : floor) for (auto& coordinate : line) std::cin >> coordinate.y >> coordinate.x;
	std::vector<std::vector<std::vector<Coordinate>>> step{ floor };
	for (auto i = 1; i < h * w; i <<= 1) {
		std::vector<std::vector<Coordinate>> new_floor(h, std::vector<Coordinate>(w));
		const auto& back = step.back();
		for (auto y = 0; y < h; ++y) for (auto x = 0; x < w; ++x) {
			auto next = back[y][x];
			new_floor[y][x] = back[next.y][next.x];
		}
		step.push_back(new_floor);
	}
	std::vector<Coordinate> dancers(n); for (auto& dancer : dancers) std::cin >> dancer.y >> dancer.x;
	std::vector<std::vector<int>> exists(h, std::vector<int>(w, -1));
	bool has_collision = false;
	for (const auto& dancer : dancers) {
		auto current_pos = step.back()[dancer.y][dancer.x];
		if (exists[current_pos.y][current_pos.x] != -1) {
			has_collision = true;
			break;
		}
		else {
			exists[current_pos.y][current_pos.x] = h * w + 1;
		}
	}
	if (!has_collision) {
		std::cout << -1 << '\n';
		return 0;
	}
	int min = 0;
	int max = h * w;
	while (min < max) {
		auto mid = (min + max) / 2;
		has_collision = false;
		for (auto dancer : dancers) {
			for (auto i = 0; i < step.size(); ++i) {
				if ((mid & (1 << i)) != 0) {
					dancer = step[i][dancer.y][dancer.x];
				}
			}
			if (exists[dancer.y][dancer.x] == mid) {
				has_collision = true;
				break;
			}
			else {
				exists[dancer.y][dancer.x] = mid;
			}
		}
		if (has_collision) max = mid;
		else min = mid + 1;
	}
	std::cout << max << '\n';
}
