#include <bits/stdc++.h>
using namespace std;
int n, m, k, s;
int X[110110];
int Mx[15], My[15], mx[15], my[15];
int z, ans;
int main() {
  while (~scanf("%d%d%d%d", &n, &m, &k, &s)) {
    ans = 0;
    for (int i = 1; i < 10; i++) {
      Mx[i] = My[i] = -10000;
      mx[i] = my[i] = 10000;
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        scanf("%d", &z);
        Mx[z] = max(Mx[z], i + j);
        My[z] = max(My[z], i - j);
        mx[z] = min(mx[z], i + j);
        my[z] = min(my[z], i - j);
      }
    for (int i = 0; i < s; i++) scanf("%d", &X[i]);
    int a, b;
    for (int i = 0; i < s - 1; i++) {
      a = X[i];
      b = X[i + 1];
      ans = max(ans, max(abs(Mx[a] - mx[b]), abs(Mx[b] - mx[a])));
      ans = max(ans, max(abs(My[a] - my[b]), abs(My[b] - my[a])));
    }
    printf("%d\n", ans);
  }
  return 0;
}
