#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e5 + 9;
long long n, m, k, st;
struct val {
  pair<long long, long long> ponta1 = {INF, INF};
  pair<long long, long long> ponta2 = {-1, INF};
  pair<long long, long long> ponta3 = {INF, -1};
  pair<long long, long long> ponta4 = {-1, -1};
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k >> st;
  long long mat[n + 2][m + 2];
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (m); ++j) {
      cin >> mat[i][j];
    }
  }
  vector<int> seq;
  vector<val> nums(10);
  for (long long i = 0; i < (st); ++i) {
    long long a;
    cin >> a;
    seq.push_back(a);
  }
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (m); ++j) {
      long long nume = mat[i][j];
      if (i + j < nums[nume].ponta1.first + nums[nume].ponta1.second) {
        nums[nume].ponta1.first = i;
        nums[nume].ponta1.second = j;
      }
      if (abs(n - i) + j <
          abs(n - nums[nume].ponta2.first) + nums[nume].ponta2.second) {
        nums[nume].ponta2.first = i;
        nums[nume].ponta2.second = j;
      }
      if (i + abs(m - j) <
          nums[nume].ponta3.first + abs(m - nums[nume].ponta3.second)) {
        nums[nume].ponta3.first = i;
        nums[nume].ponta3.second = j;
      }
      if (abs(n - i) + abs(m - j) < abs(n - nums[nume].ponta4.first) +
                                        abs(m - nums[nume].ponta4.second)) {
        nums[nume].ponta4.first = i;
        nums[nume].ponta4.second = j;
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < ((long long)(seq).size() - 1); ++i) {
    ans = max(
        ans,
        abs(nums[seq[i]].ponta1.first - nums[seq[i + 1]].ponta1.first) +
            abs(nums[seq[i]].ponta1.second - nums[seq[i + 1]].ponta1.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta1.first - nums[seq[i + 1]].ponta2.first) +
            abs(nums[seq[i]].ponta1.second - nums[seq[i + 1]].ponta2.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta1.first - nums[seq[i + 1]].ponta3.first) +
            abs(nums[seq[i]].ponta1.second - nums[seq[i + 1]].ponta3.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta1.first - nums[seq[i + 1]].ponta4.first) +
            abs(nums[seq[i]].ponta1.second - nums[seq[i + 1]].ponta4.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta2.first - nums[seq[i + 1]].ponta1.first) +
            abs(nums[seq[i]].ponta2.second - nums[seq[i + 1]].ponta1.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta2.first - nums[seq[i + 1]].ponta2.first) +
            abs(nums[seq[i]].ponta2.second - nums[seq[i + 1]].ponta2.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta2.first - nums[seq[i + 1]].ponta3.first) +
            abs(nums[seq[i]].ponta2.second - nums[seq[i + 1]].ponta3.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta2.first - nums[seq[i + 1]].ponta4.first) +
            abs(nums[seq[i]].ponta2.second - nums[seq[i + 1]].ponta4.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta3.first - nums[seq[i + 1]].ponta1.first) +
            abs(nums[seq[i]].ponta3.second - nums[seq[i + 1]].ponta1.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta3.first - nums[seq[i + 1]].ponta2.first) +
            abs(nums[seq[i]].ponta3.second - nums[seq[i + 1]].ponta2.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta3.first - nums[seq[i + 1]].ponta3.first) +
            abs(nums[seq[i]].ponta3.second - nums[seq[i + 1]].ponta3.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta3.first - nums[seq[i + 1]].ponta4.first) +
            abs(nums[seq[i]].ponta3.second - nums[seq[i + 1]].ponta4.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta4.first - nums[seq[i + 1]].ponta1.first) +
            abs(nums[seq[i]].ponta4.second - nums[seq[i + 1]].ponta1.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta4.first - nums[seq[i + 1]].ponta2.first) +
            abs(nums[seq[i]].ponta4.second - nums[seq[i + 1]].ponta2.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta4.first - nums[seq[i + 1]].ponta3.first) +
            abs(nums[seq[i]].ponta4.second - nums[seq[i + 1]].ponta3.second));
    ans = max(
        ans,
        abs(nums[seq[i]].ponta4.first - nums[seq[i + 1]].ponta4.first) +
            abs(nums[seq[i]].ponta4.second - nums[seq[i + 1]].ponta4.second));
  }
  cout << ans << "\n";
  return 0;
}
