#include <bits/stdc++.h>
using namespace std;
bool mp[10][10];
int maxt[10][4];
inline void init(int k) {
  for (int i = 1; i <= k; ++i)
    maxt[i][0] = maxt[i][1] = maxt[i][2] = maxt[i][3] = -0x3f3f3f3f;
}
int main() {
  int i, j, n, m, k, s;
  scanf("%d%d%d%d", &n, &m, &k, &s);
  init(k);
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      int x;
      scanf("%d", &x);
      maxt[x][0] = max(maxt[x][0], -i - j);
      maxt[x][1] = max(maxt[x][1], -i + j);
      maxt[x][2] = max(maxt[x][2], i - j);
      maxt[x][3] = max(maxt[x][3], i + j);
    }
  memset(mp, 0, sizeof(mp));
  int pre, num;
  scanf("%d", &pre);
  for (i = 1; i < s; ++i) {
    scanf("%d", &num);
    mp[pre][num] = mp[num][pre] = 1;
    pre = num;
  }
  int ans = 0;
  for (i = 1; i <= k; ++i)
    for (j = i; j <= k; ++j)
      if (mp[i][j]) {
        if (i == j) {
          ans = max(ans, maxt[i][0] + maxt[i][3]);
          ans = max(ans, maxt[i][1] + maxt[i][2]);
        } else {
          ans = max(ans, maxt[i][0] + maxt[j][3]);
          ans = max(ans, maxt[i][1] + maxt[j][2]);
          ans = max(ans, maxt[i][2] + maxt[j][1]);
          ans = max(ans, maxt[i][3] + maxt[j][0]);
        }
      }
  printf("%d\n", ans);
  return 0;
}
