#include <bits/stdc++.h>
using namespace std;
int n, m, k, s, bigx[11], bigy[11], smlx[11], smly[11];
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (int i = 1; i <= k; i++)
    bigx[i] = bigy[i] = -2020, smlx[i] = smly[i] = 2 * 2020;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) {
      int t;
      scanf("%d", &t);
      bigx[t] = max(bigx[t], i + j);
      bigy[t] = max(bigy[t], i - j);
      smlx[t] = min(smlx[t], i + j);
      smly[t] = min(smly[t], i - j);
    }
  int a, b, ans = -1;
  scanf("%d", &a);
  for (int i = 1; i < s; i++) {
    scanf("%d", &b);
    ans = max(ans, max(abs(bigx[a] - smlx[b]), abs(bigx[b] - smlx[a])));
    ans = max(ans, max(abs(bigy[a] - smly[b]), abs(bigy[b] - smly[a])));
    a = b;
  }
  printf("%d\n", ans);
  return 0;
}
