#include <bits/stdc++.h>
using namespace std;
const int maxn = 2002;
const int maxm = 100001;
const int inf = 1000 * 1000 * 1000;
int n, m, k, s, a[maxn][maxn], d[2][2][9][maxn], dis[9][9], ans, t1, t2;
int main() {
  cin >> n >> m >> k >> s;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      a[i][j]--;
    }
  for (int K = 0; K < k; K++)
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < maxn; j++) d[i][0][K][j] = d[i][1][K][j] = -inf;
  for (int K = 0; K < k; K++)
    for (int i = n; i > 0; i--) {
      for (int j = m; j > 0; j--) {
        d[0][0][K][j] = max((a[i][j] == K ? i + j : -inf),
                            max(d[1][0][K][j], d[0][0][K][j + 1]));
        d[0][1][K][m - j + 1] =
            max((a[i][m - j + 1] == K ? i - m + j - 1 : -inf),
                max(d[1][1][K][m - j + 1], d[0][1][K][m - j]));
      }
      for (int j = 1; j <= m; j++) {
        dis[a[i][j]][K] = max(
            dis[a[i][j]][K], max(d[0][0][K][j] - i - j, d[0][1][K][j] - i + j));
        dis[K][a[i][j]] = dis[a[i][j]][K];
        d[1][0][K][j] = d[0][0][K][j];
        d[1][1][K][j] = d[0][1][K][j];
      }
    }
  cin >> t1;
  t1--;
  for (int i = 2; i <= s; i++) {
    cin >> t2;
    t2--;
    ans = max(ans, dis[t1][t2]);
    t1 = t2;
  }
  cout << ans;
  return 0;
}
