#include <bits/stdc++.h>
using namespace std;
int Max[10][5];
int main() {
  int i, j, n, m, k, s, x, last, now, ans;
  while (scanf("%d %d %d %d", &n, &m, &k, &s) != EOF) {
    ans = 0;
    for (i = 1; i <= k; i++)
      for (j = 0; j < 4; j++) Max[i][j] = -1 << 30;
    for (i = 1; i <= n; i++)
      for (j = 1; j <= m; j++) {
        scanf("%d", &x);
        Max[x][0] = max(Max[x][0], i + j);
        Max[x][1] = max(Max[x][1], i - j);
        Max[x][2] = max(Max[x][2], -i + j);
        Max[x][3] = max(Max[x][3], -i - j);
      }
    scanf("%d", &last);
    for (i = 1; i < s; i++) {
      scanf("%d", &now);
      ans = max(ans, Max[last][0] + Max[now][3]);
      ans = max(ans, Max[last][1] + Max[now][2]);
      ans = max(ans, Max[last][2] + Max[now][1]);
      ans = max(ans, Max[last][3] + Max[now][0]);
      last = now;
    }
    printf("%d", ans);
  }
  return 0;
}
