#include <bits/stdc++.h>
using namespace std;
int n, m, k, s, best[10][10], mini[2048][10], maxi[2048][10];
int main() {
  while (scanf("%d%d%d%d", &n, &m, &k, &s) != EOF) {
    memset(best, 0, sizeof(best));
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= k; j++) {
        mini[i][j] = m;
        maxi[i][j] = -1;
      }
      for (int j = 0; j < m; j++) {
        int temp;
        scanf("%d", &temp);
        if (mini[i][temp] == m) {
          mini[i][temp] = j;
        }
        maxi[i][temp] = j;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        for (int p = 1; p <= k; p++) {
          for (int q = 1; q <= k; q++) {
            if (mini[i][p] != m && maxi[j][q] != -1) {
              best[p][q] =
                  max(best[p][q], (j - i) + abs(maxi[j][q] - mini[i][p]));
            }
            if (maxi[i][p] != -1 && mini[j][q] != m) {
              best[p][q] =
                  max(best[p][q], (j - i) + abs(maxi[i][p] - mini[j][q]));
            }
            if (mini[i][p] != m && mini[j][q] != m) {
              best[p][q] =
                  max(best[p][q], (j - i) + abs(mini[i][p] - mini[j][q]));
            }
            if (maxi[i][p] != -1 && maxi[j][q] != -1) {
              best[p][q] =
                  max(best[p][q], (j - i) + abs(maxi[i][p] - maxi[j][q]));
            }
          }
        }
      }
    }
    int cur, pre = -1;
    int ans = 0;
    for (int i = 0; i < s; i++) {
      scanf("%d", &cur);
      if (pre != -1) {
        ans = max(ans, max(best[cur][pre], best[pre][cur]));
      }
      pre = cur;
    }
    printf("%d\n", ans);
  }
  return 0;
}
