#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
int n, m, k, s;
vector<int> adj[12];
vector<int> adj2[12];
int diff[12][12];
int calc(int x, int y) {
  if (adj[x].size() == 0 || adj[y].size() == 0) return -1;
  int ans = 0;
  int B1 = adj[x][0];
  int B2 = adj[y][0];
  int E1 = adj[x].back();
  int E2 = adj[y].back();
  return max(abs(B1 - E2), abs(B2 - E1));
}
int calc2(int x, int y) {
  if (adj2[x].size() == 0 || adj2[y].size() == 0) return -1;
  int ans = 0;
  int B1 = adj2[x][0];
  int B2 = adj2[y][0];
  int E1 = adj2[x].back();
  int E2 = adj2[y].back();
  return max(abs(B1 - E2), abs(B2 - E1));
}
int main() {
  scanf("%d %d %d %d", &n, &m, &k, &s);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x;
      scanf("%d", &x);
      adj[x].push_back(i + m - j + 1);
      adj2[x].push_back(i + j);
    }
  }
  for (int i = 1; i <= k; i++) {
    sort(adj[i].begin(), adj[i].end());
    sort(adj2[i].begin(), adj2[i].end());
  }
  for (int i = 1; i <= k; i++) {
    for (int j = i; j <= k; j++) {
      diff[i][j] = diff[j][i] = max(diff[i][j], max(calc(i, j), calc2(i, j)));
    }
  }
  int ans = 0;
  int x, prvx = -1;
  while (s--) {
    scanf("%d", &x);
    if (prvx != -1) {
      ans = max(ans, diff[x][prvx]);
    }
    prvx = x;
  }
  printf("%d\n", ans);
}
