#include <bits/stdc++.h>
using namespace std;
int n, m, k, s;
int a[2222][10] = {0}, b[2222][10] = {0};
int q[155555] = {0}, dist[10][10] = {0};
int main() {
  cin >> n >> m >> k >> s;
  memset(a, 127, sizeof(a));
  memset(b, 0, sizeof(a));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int x;
      cin >> x;
      if (j > b[i][x]) b[i][x] = j;
      if (j < a[i][x]) a[i][x] = j;
    }
  for (int x = 1; x <= k; x++)
    for (int y = 1; y <= k; y++)
      for (int i = 1; i <= n; i++) {
        if (a[i][x] > m || b[i][x] < 1) continue;
        for (int j = n; j >= i; j--) {
          if (a[j][y] > m || b[j][y] < 1) continue;
          dist[x][y] = max(dist[x][y], j - i + abs(a[i][x] - b[j][y]));
          dist[x][y] = max(dist[x][y], j - i + abs(b[i][x] - a[j][y]));
          if (dist[x][y] > j - i + 1 + m) break;
        }
      }
  int ans = 0;
  for (int i = 0; i < s; i++) {
    cin >> q[i];
    if (i > 0) ans = max(ans, dist[q[i]][q[i - 1]]);
  }
  cout << ans << endl;
}
