#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int num[100][4];
int main() {
  int n, m, k, s, a, x, y, ans = -inf, i, j;
  scanf("%d%d%d%d", &n, &m, &k, &s);
  memset(num, 1000, sizeof(num));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      scanf("%d", &a);
      num[a][0] = max(num[a][0], -i - j);
      num[a][1] = max(num[a][1], -i + j);
      num[a][2] = max(num[a][2], i - j);
      num[a][3] = max(num[a][3], i + j);
    }
  }
  scanf("%d", &x);
  for (i = 2; i <= s; i++) {
    scanf("%d", &y);
    for (j = 0; j <= 3; j++) {
      ans = max(ans, num[x][j] + num[y][3 - j]);
    }
    x = y;
  }
  printf("%d", ans);
}
