#include <bits/stdc++.h>
using namespace std;
int a[2010][2010], q[100010], gx[10][4], gy[10][4];
int main() {
  int n, m, k, s;
  scanf("%d%d", &(n), &(m));
  scanf("%d%d", &(k), &(s));
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++) scanf("%d", &(a[i][j]));
  for (int i = (int)(1); i <= (int)(s); i++) scanf("%d", &(q[i]));
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++)
      for (int ii = 0; ii < (int)(4); ii++) {
        int v = a[i][j];
        gx[v][ii] = i;
        gy[v][ii] = j;
      }
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++) {
      int v = a[i][j];
      if (i + j < gx[v][0] + gy[v][0]) gx[v][0] = i, gy[v][0] = j;
      if (i + j > gx[v][1] + gy[v][1]) gx[v][1] = i, gy[v][1] = j;
      if (i - j < gx[v][2] - gy[v][2]) gx[v][2] = i, gy[v][2] = j;
      if (i - j > gx[v][3] - gy[v][3]) gx[v][3] = i, gy[v][3] = j;
    }
  int ans = 0;
  for (int i = (int)(1); i <= (int)(s - 1); i++) {
    int v1 = q[i];
    int v2 = q[i + 1];
    for (int ii = 0; ii < (int)(4); ii++)
      for (int jj = 0; jj < (int)(4); jj++) {
        int x1 = gx[v1][ii];
        int y1 = gy[v1][ii];
        int x2 = gx[v2][jj];
        int y2 = gy[v2][jj];
        ans = max(ans, abs(x1 - x2) + abs(y1 - y2));
      }
  }
  printf("%d\n", ans);
  return 0;
}
