#include <bits/stdc++.h>
using namespace std;
int a[2000][2000], dp[10][10], mark[10][2000][2], b[100000];
int main() {
  int n, m, k, s, i, j, l, ans = 0, val;
  scanf("%d%d%d%d", &n, &m, &l, &s);
  memset(mark, -1, sizeof(mark));
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
      if (mark[a[i][j]][i][0] == -1) mark[a[i][j]][i][0] = j;
      if (mark[a[i][j]][i][1] == -1)
        mark[a[i][j]][i][1] = j;
      else {
        mark[a[i][j]][i][0] = min(mark[a[i][j]][i][0], j);
        mark[a[i][j]][i][1] = max(mark[a[i][j]][i][1], j);
      }
    }
  }
  for (i = 0; i < s; i++) scanf("%d", &b[i]);
  for (i = 1; i < s; i++) {
    if (dp[b[i]][b[i - 1]] != 0) continue;
    for (j = 0; j < n; j++) {
      for (k = 0; k < n; k++) {
        val = 0;
        if (mark[b[i]][j][0] == -1) break;
        if (mark[b[i - 1]][k][0] == -1)
          continue;
        else {
          val = abs(mark[b[i]][j][0] - mark[b[i - 1]][k][0]);
          val = max(val, abs(mark[b[i]][j][0] - mark[b[i - 1]][k][1]));
          val = max(val, abs(mark[b[i]][j][1] - mark[b[i - 1]][k][0]));
          dp[b[i]][b[i - 1]] = max(dp[b[i]][b[i - 1]], val + abs(j - k));
          dp[b[i - 1]][b[i]] = dp[b[i]][b[i - 1]];
        }
      }
    }
    ans = max(ans, dp[b[i]][b[i - 1]]);
  }
  printf("%d\n", ans);
  return 0;
}
