#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
struct note {
  int pa, pi, sa, si;
};
note g[100];
int n, m, x, ma, k, s;
int s1, s2;
int max4(int a, int b, int c, int d) { return max(a, max(b, max(c, d))); }
int main() {
  int i, j;
  int T;
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (i = 1; i <= k; i++) {
    g[i].pa = g[i].sa = -1;
    g[i].pi = g[i].si = 100000000;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%d", &x);
      g[x].pa = max(g[x].pa, i + j);
      g[x].pi = min(g[x].pi, i + j);
      g[x].sa = max(g[x].sa, i - j);
      g[x].si = min(g[x].si, i - j);
    }
  }
  ma = 0;
  scanf("%d", &s1);
  for (i = 1; i < s; i++) {
    scanf("%d", &s2);
    ma = max(ma, max4(g[s1].pa - g[s2].pi, g[s1].sa - g[s2].si,
                      g[s2].sa - g[s1].si, g[s2].pa - g[s1].pi));
    s1 = s2;
  }
  printf("%d\n", ma);
  return 0;
}
