#include <bits/stdc++.h>
using namespace std;
int n, m, k, s, ans, x, y, f[11][4][2];
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (int i = 1; i <= k; i++)
    for (int j = 0; j < 4; j++) {
      f[i][j][0] = 1000000000;
      f[i][j][1] = -1000000000;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &x);
      f[x][0][0] = min(f[x][0][0], -i - j);
      f[x][0][1] = max(f[x][0][1], -i - j);
      f[x][1][0] = min(f[x][1][0], -i + j);
      f[x][1][1] = max(f[x][1][1], -i + j);
      f[x][2][0] = min(f[x][2][0], i - j);
      f[x][2][1] = max(f[x][2][1], i - j);
      f[x][3][0] = min(f[x][3][0], i + j);
      f[x][3][1] = max(f[x][3][1], i + j);
    }
  scanf("%d", &y);
  for (int i = 2; i <= s; i++) {
    x = y;
    scanf("%d", &y);
    for (int j = 0; j < 4; j++) {
      ans = max(ans, f[x][j][1] - f[y][j][0]);
      ans = max(ans, f[y][j][1] - f[x][j][0]);
    }
  }
  printf("%d\n", ans);
}
