#include <bits/stdc++.h>
using namespace std;
int n, m, k, s, i, j, ll[1000000], rr[1000000], a[2010][2010], u, v, l, uu, vv,
    f[100][100], ans, w[1000000];
int abs(int x) {
  if (x < 0) x = -x;
  return x;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (i = 1; i <= k; i++) {
    ll[i] = 0x37373737;
    rr[i] = ll[i];
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      u = i + j;
      v = i + (m - j + 1);
      for (l = 1; l <= k; l++) {
        if (ll[l] != 0x37373737) {
          uu = abs(ll[l] - u);
          if (uu > f[l][a[i][j]]) {
            f[l][a[i][j]] = uu;
            f[a[i][j]][l] = uu;
          }
        }
        if (rr[l] != 0x37373737) {
          vv = abs(rr[l] - v);
          if (vv > f[l][a[i][j]]) {
            f[l][a[i][j]] = vv;
            f[a[i][j]][l] = vv;
          }
        }
      }
      if (u < ll[a[i][j]]) ll[a[i][j]] = u;
      if (v < rr[a[i][j]]) rr[a[i][j]] = v;
    }
  for (i = 1; i <= s; i++) {
    scanf("%d", &w[i]);
    if (i > 1)
      if (f[w[i]][w[i - 1]] > ans) ans = f[w[i]][w[i - 1]];
  }
  printf("%d", ans);
}
