#include <bits/stdc++.h>
using namespace std;
const long long ll_INF = ((unsigned long long)(-1)) >> 1;
const int INF = 100000000;
const double EPS = 1e-8;
int ABS(int x) { return x >= 0 ? x : (-x); }
int a[10][4][2];
int n, m, k, s;
int main() {
  int x, y;
  while (~scanf("%d%d%d%d", &n, &m, &k, &s)) {
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 4; j++) {
        a[i][j][0] = INF;
        a[i][j][1] = -INF;
      }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        scanf("%d", &x);
        a[x][0][0] = min(a[x][0][0], -i - j);
        a[x][0][1] = max(a[x][0][1], -i - j);
        a[x][1][0] = min(a[x][1][0], -i + j);
        a[x][1][1] = max(a[x][1][1], -i + j);
        a[x][2][0] = min(a[x][2][0], i - j);
        a[x][2][1] = max(a[x][2][1], i - j);
        a[x][3][0] = min(a[x][3][0], i + j);
        a[x][3][1] = max(a[x][3][1], i + j);
      }
    int ans = 0;
    scanf("%d", &x);
    for (int i = 1; i < s; i++) {
      scanf("%d", &y);
      for (int j = 0; j < 4; j++) {
        ans = max(ans, ABS(a[x][j][1] - a[y][j][0]));
        ans = max(ans, ABS(a[x][j][0] - a[y][j][1]));
      }
      x = y;
    }
    printf("%d\n", ans);
  }
  return 0;
}
