#include <bits/stdc++.h>
using namespace std;
int n, m, k, s;
int f[10][2], b[10][2];
int max5(int a, int b, int c, int d, int e) {
  return max(a, max(max(b, c), max(d, e)));
}
int main() {
  memset(f, 192, sizeof(f));
  memset(b, 63, sizeof(b));
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int a;
      scanf("%d", &a);
      f[a][0] = max(f[a][0], i + j);
      f[a][1] = max(f[a][1], i - j);
      b[a][0] = min(b[a][0], i + j);
      b[a][1] = min(b[a][1], i - j);
    }
  }
  int p, q, ans = 0;
  for (int i = 0; i < s; i++, p = q) {
    scanf("%d", &q);
    if (i) {
      int t1 = f[p][0] - b[q][0];
      int t2 = f[q][1] - b[p][1];
      int t3 = f[p][1] - b[q][1];
      int t4 = f[q][0] - b[p][0];
      ans = max5(ans, t1, t2, t3, t4);
    }
  }
  printf("%d\n", ans);
  return 0;
}
