#include <bits/stdc++.h>
using namespace std;
int N, M, K, S;
int minsum[(10)];
int maxsum[(10)];
int mindiff[(10)];
int maxdiff[(10)];
int main() {
  int i, j;
  scanf("%d %d %d %d", &N, &M, &K, &S);
  for (i = 1; i <= K; ++i) {
    minsum[i] = 10000;
    maxsum[i] = -10000;
    mindiff[i] = 10000;
    maxdiff[i] = -10000;
  }
  for (i = 0; i < N; ++i) {
    for (j = 0; j < M; ++j) {
      int a;
      scanf("%d", &a);
      int sum = i + j;
      int diff = i - j;
      minsum[a] = min(minsum[a], sum);
      maxsum[a] = max(maxsum[a], sum);
      mindiff[a] = min(mindiff[a], diff);
      maxdiff[a] = max(maxdiff[a], diff);
    }
  }
  int sol = 0;
  int a;
  scanf("%d", &a);
  for (i = 1; i < S; ++i) {
    int b;
    scanf("%d", &b);
    sol = max(sol, max(abs(minsum[a] - maxsum[b]), abs(maxsum[a] - minsum[b])));
    sol = max(sol,
              max(abs(mindiff[a] - maxdiff[b]), abs(maxdiff[a] - mindiff[b])));
    a = b;
  }
  printf("%d\n", sol);
  return 0;
}
