#include <bits/stdc++.h>
int n, m, k, s;
int a[2005][2005];
int b[100005];
int c[2005][10], d[2005][10];
int map[2005][2005];
int f(int x) { return x > 0 ? x : -x; }
int main() {
  int i, j, p, q, com, ans;
  while (~scanf("%d%d%d%d", &n, &m, &k, &s)) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(map, 0, sizeof(map));
    memset(c, 0, sizeof(c));
    memset(d, 0, sizeof(d));
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++)
        if (!c[i][a[i][j]]) c[i][a[i][j]] = j + 1;
    }
    for (i = 0; i < n; i++) {
      for (j = m - 1; j >= 0; j--)
        if (!d[i][a[i][j]]) d[i][a[i][j]] = j + 1;
    }
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++)
        for (p = 1; p <= k; p++)
          for (q = 1; q <= k; q++) {
            com = map[p][q];
            if (d[i][p] && c[j][q])
              com = com > (f(d[i][p] - c[j][q]) + (j - i))
                        ? com
                        : (f(d[i][p] - c[j][q]) + (j - i));
            if (c[i][p] && d[j][q])
              com = com > (f(c[i][p] - d[j][q]) + (j - i))
                        ? com
                        : (f(c[i][p] - d[j][q]) + (j - i));
            map[q][p] = com;
          }
    for (i = 0; i < s; i++) scanf("%d", &b[i]);
    ans = 0;
    for (i = 1; i < s; i++)
      ans = ans > map[b[i - 1]][b[i]] ? ans : map[b[i - 1]][b[i]];
    printf("%d\n", ans);
  }
  return 0;
}
