#include <bits/stdc++.h>
using namespace std;
int fi[10][2002], se[10][2002];
int a[2002][2002];
int q[100002];
bool vis[10][10];
int main() {
  int n, m, k, s;
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      if (fi[a[i][j]][i] == 0) fi[a[i][j]][i] = j;
      se[a[i][j]][i] = j;
    }
  for (int i = 1; i <= s; i++) scanf("%d", &q[i]);
  for (int i = 2; i <= s; i++) vis[q[i - 1]][q[i]] = vis[q[i]][q[i - 1]] = 1;
  int ans = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      if (!vis[i][j]) continue;
      for (int r1 = 1; r1 <= n; r1++) {
        if (fi[i][r1] == 0) continue;
        for (int r2 = r1; r2 <= n; r2++) {
          if (fi[j][r2] == 0) continue;
          ans = max(ans, abs(r2 - r1) + abs(fi[i][r1] - fi[j][r2]));
          ans = max(ans, abs(r2 - r1) + abs(fi[i][r1] - se[j][r2]));
          ans = max(ans, abs(r2 - r1) + abs(se[i][r1] - fi[j][r2]));
          ans = max(ans, abs(r2 - r1) + abs(se[i][r1] - se[j][r2]));
        }
      }
    }
  }
  printf("%d\n", ans);
}
