#include <bits/stdc++.h>
using namespace std;
const int N = 2222;
const int INF = 0x3f3f3f3f;
int n, m, k, s;
int mat[2][N][9], cp[9][9];
void tomin(int &a, int b) {
  if (a > b) a = b;
}
void tomax(int &a, int b) {
  if (a < b) a = b;
}
void work() {
  for (int i = 0; i < m; i++)
    for (int j = 0; j < k; j++) {
      for (int r = 0; r < m; r++)
        for (int p = 0; p < k; p++) {
          if (mat[1][i][j] != -1 && mat[0][r][p] != INF)
            tomax(cp[j][p], abs(r - i) + mat[1][i][j] - mat[0][r][p]);
          if (mat[1][r][p] != -1 && mat[0][i][j] != INF)
            tomax(cp[j][p], abs(r - i) + mat[1][r][p] - mat[0][i][j]);
        }
    }
  int d, ans = 0;
  scanf("%d", &d);
  d--;
  for (int i = 1; i < s; i++) {
    int x;
    scanf("%d", &x);
    x--;
    tomax(ans, cp[d][x]);
    d = x;
  }
  printf("%d\n", ans);
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &s);
  memset(mat[0], INF, sizeof(mat[0]));
  memset(mat[1], -1, sizeof(mat[1]));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int d;
      scanf("%d", &d);
      d--;
      tomin(mat[0][j][d], i);
      tomax(mat[1][j][d], i);
    }
  work();
  return 0;
}
