#include <bits/stdc++.h>
using namespace std;
int n, m, k, s;
int a[2020][2020];
int d[10][4];
int dist[10][10];
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (int i = 1; i <= k; i++) {
    d[i][0] = 1e9;
    d[i][1] = 1e9;
    d[i][2] = -1e9;
    d[i][3] = -1e9;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      d[a[i][j]][0] = min(d[a[i][j]][0], i + j);
      d[a[i][j]][1] = min(d[a[i][j]][1], i - j);
      d[a[i][j]][2] = max(d[a[i][j]][2], i + j);
      d[a[i][j]][3] = max(d[a[i][j]][3], i - j);
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int v = a[i][j];
      for (int kk = 1; kk <= k; kk++) {
        int now = 0;
        now = max(now, (i + j) - d[kk][0]);
        now = max(now, (i - j) - d[kk][1]);
        now = max(now, d[kk][2] - (i + j));
        now = max(now, d[kk][3] - (i - j));
        dist[v][kk] = max(dist[v][kk], now);
      }
    }
  int ret = 0;
  int prev = 0;
  for (int i = 1; i <= s; i++) {
    int x;
    scanf("%d", &x);
    ret = max(ret, dist[x][prev]);
    prev = x;
  }
  printf("%d", ret);
  return 0;
}
