#include <bits/stdc++.h>
int min(int x, int y) {
  if (x > y)
    return y;
  else
    return x;
}
int max(int x, int y) {
  if (x > y)
    return x;
  else
    return y;
}
int main(void) {
  int n, m, k, s, i, j, u, f[10][2], g[10][2], ans = 0;
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (i = 1; i <= k; i++) {
    g[i][0] = n + m;
    g[i][1] = n - 1;
    f[i][0] = 0;
    f[i][1] = 1 - m;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      scanf("%d", &u);
      f[u][0] = max(i + j, f[u][0]);
      g[u][0] = min(i + j, g[u][0]);
      f[u][1] = max(i - j, f[u][1]);
      g[u][1] = min(i - j, g[u][1]);
    }
  }
  for (u = 0; u < s; u++, n = m) {
    scanf("%d", &m);
    if (u)
      ans = max(ans, max(max(f[n][0] - g[m][0], f[m][0] - g[n][0]),
                         max(f[n][1] - g[m][1], f[m][1] - g[n][1])));
  }
  printf("%d", ans);
  return 0;
}
