#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 7;
const int K = 9 + 5;
int n, m, k, s;
short tab[N][N];
int dist[K][K];
pair<int, int> first[K];
void clear() {
  for (int i = 0; i < (K); ++i) first[i].first = first[i].second = -1;
}
bool found(int z) { return first[z].first != -1; }
int di(pair<int, int> a, pair<int, int> b) {
  return abs(a.first - b.first) + abs(b.second - a.second);
}
void update(int x, int y) {
  int val = tab[x][y];
  if (!found(val)) first[val] = make_pair(x, y);
  for (int i = 0; i < (k + 1); ++i) {
    if (i && found(i))
      dist[i][val] = dist[val][i] =
          max(dist[i][val], di(first[i], make_pair(x, y)));
  }
}
int main() {
  scanf("%d %d %d %d", &n, &m, &k, &s);
  for (int i = 0; i < (K); ++i)
    for (int j = 0; j < (K); ++j) dist[i][i] = 0;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) scanf("%hd", &tab[i][j]);
  clear();
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) update(i, j);
  clear();
  for (int j = 0; j < (m); ++j)
    for (int i = 0; i < (n); ++i) update(i, j);
  clear();
  for (int z = 0; z < n; z++) {
    int i = z, j = 0;
    while (i >= 0 && j < m) {
      update(i, j);
      i--;
      j++;
    }
  }
  for (int z = 1; z < m; z++) {
    int i = n - 1, j = z;
    while (j < m && i >= 0) {
      update(i, j);
      i--;
      j++;
    }
  }
  clear();
  for (int z = n - 1; z >= 0; z--) {
    int i = z, j = 0;
    while (i < n && j < m) {
      update(i, j);
      i++;
      j++;
    }
  }
  for (int z = 1; z < m; z++) {
    int i = 0, j = z;
    while (i < n && j < m) {
      update(i, j);
      i++;
      j++;
    }
  }
  int ans = -1;
  int last = -1, act;
  for (int i = 0; i < (s); ++i) {
    scanf("%d", &act);
    if (last != -1) ans = max(ans, dist[last][act]);
    last = act;
  }
  printf("%d\n", ans);
  return 0;
}
