#include <bits/stdc++.h>
using namespace std;
int n, m, k, s;
int LUX[10], LUY[10], LDX[10], LDY[10], ULX[10], ULY[10], URX[10], URY[10],
    DLX[10], DLY[10], DRX[10], DRY[10], RUX[10], RUY[10], RDX[10], RDY[10];
bool found[10];
vector<pair<int, int> > pt[10];
int dist[10][10];
int L[2010][10], R[2010][10];
int main() {
  scanf("%d %d %d %d", &n, &m, &k, &s);
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j < 10; ++j) {
      L[i][j] = m + 1;
      R[i][j] = -1;
    }
    for (int j = 0; j < m; ++j) {
      int x;
      scanf("%d", &x);
      if (L[i][x] > j) L[i][x] = j;
      if (R[i][x] < j) R[i][x] = j;
    }
  }
  for (int i = 1; i < 10; ++i) {
    for (int j = i; j < 10; ++j) {
      for (int k = 0; k < n; ++k) {
        for (int l = 0; l < n; ++l) {
          if (L[k][i] != m + 1 && R[l][j] != -1)
            dist[i][j] = max(dist[i][j], abs(l - k) + abs(L[k][i] - R[l][j]));
          if (R[k][i] != -1 && L[l][j] != m + 1)
            dist[i][j] = max(dist[i][j], abs(l - k) + abs(R[k][i] - L[l][j]));
        }
      }
    }
  }
  int ans = 0;
  int last = -1;
  for (int i = 0; i < s; ++i) {
    int now;
    scanf("%d", &now);
    if (last != -1) {
      ans = max(ans, dist[min(last, now)][max(last, now)]);
    }
    last = now;
  }
  printf("%d\n", ans);
}
