#include <bits/stdc++.h>
int main() {
  int n, m, k, s, t, i, j, ii, jj, temp = 0, max = 0, n1, n2;
  scanf("%d %d %d %d\n", &n, &m, &k, &s);
  int w[20][20], **a, **l, **r, *q;
  l = (int**)malloc(sizeof(int*) * 10);
  r = (int**)malloc(sizeof(int*) * 10);
  a = (int**)malloc(sizeof(int*) * (n + 1));
  q = (int*)malloc(sizeof(int) * (s + 1));
  for (i = 0; i < 10; i++) {
    l[i] = (int*)malloc(sizeof(int) * (n + 1));
    r[i] = (int*)malloc(sizeof(int) * (n + 1));
  }
  for (i = 0; i < n + 1; i++) a[i] = (int*)malloc(sizeof(int) * (m + 1));
  for (i = 0; i < 10; i++)
    for (j = 0; j < n + 1; j++) {
      l[i][j] = 0;
      r[i][j] = 0;
    }
  for (i = 0; i < 20; i++)
    for (j = 0; j < 20; j++) w[i][j] = 0;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      if (l[a[i][j]][i] == 0) l[a[i][j]][i] = j;
      r[a[i][j]][i] = j;
    }
  for (i = 1; i <= k; i++)
    for (j = 1; j <= k; j++)
      for (ii = 1; ii <= n; ii++)
        for (jj = 1; jj <= n; jj++) {
          if (l[i][ii] == 0 || r[j][jj] == 0)
            n1 = 0;
          else {
            n1 = abs(ii - jj) + abs(l[i][ii] - r[j][jj]);
          }
          if (l[j][jj] == 0 || r[i][ii] == 0)
            n2 = 0;
          else {
            n2 = abs(ii - jj) + abs(r[i][ii] - l[j][jj]);
          }
          temp = (n1 > n2) ? n1 : n2;
          if (w[i][j] < temp) w[i][j] = temp;
        }
  for (i = 1; i <= s; i++) scanf("%d", &q[i]);
  for (i = 2; i <= s; i++) {
    temp = w[q[i - 1]][q[i]];
    if (max < temp) max = temp;
  }
  printf("%d", max);
  return 0;
}
