#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 5;
int l[11][maxn], r[11][maxn], a[maxn][maxn], b[100000 + 10];
bool mp[11][11];
int min(int a, int b) { return a == -1 || a > b ? b : a; }
int max(int a, int b) { return a == -1 || a < b ? b : a; }
int main() {
  int n, m, k, s;
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < s; i++) scanf("%d", &b[i]);
  for (int i = 1; i < s; i++) mp[b[i - 1]][b[i]] = 1;
  memset(l, -1, sizeof(l));
  memset(r, -1, sizeof(r));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      l[a[i][j]][i] = min(l[a[i][j]][i], j);
      r[a[i][j]][i] = max(r[a[i][j]][i], j);
    }
  }
  int ans = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++)
      if (mp[i][j]) {
        for (int ii = 1; ii <= n; ii++) {
          for (int jj = 1; jj <= n; jj++)
            if (l[i][ii] != -1 && r[j][jj] != -1) {
              ans = max(ans, abs(ii - jj) + abs(l[i][ii] - r[j][jj]));
              ans = max(ans, abs(ii - jj) + abs(r[i][ii] - l[j][jj]));
            }
        }
      }
  }
  printf("%d\n", ans);
  return 0;
}
