#include <bits/stdc++.h>
using namespace std;
int R, C, K, S;
int board[2005][2005];
int minUL[10], minUR[10];
int maxUL[10], maxUR[10];
int fret[100005];
int dist[10][10];
int cal(int a, int b) {
  int ret = 0;
  ret = max(ret, abs(maxUL[b] - maxUL[a]));
  ret = max(ret, abs(maxUL[b] - minUL[a]));
  ret = max(ret, abs(minUL[b] - maxUL[a]));
  ret = max(ret, abs(minUL[b] - minUL[a]));
  ret = max(ret, abs(maxUR[b] - maxUR[a]));
  ret = max(ret, abs(maxUR[b] - minUR[a]));
  ret = max(ret, abs(minUR[b] - maxUR[a]));
  ret = max(ret, abs(minUR[b] - minUR[a]));
  return ret;
}
int main() {
  scanf("%d %d %d %d", &R, &C, &K, &S);
  for (int i = 0; i < R; i++)
    for (int j = 0; j < C; j++) scanf("%d", &board[i][j]);
  for (int i = 0; i < S; i++) scanf("%d", &fret[i]);
  for (int i = 0; i < 10; i++) {
    minUL[i] = minUR[i] = 1000000000;
    maxUL[i] = maxUR[i] = 0;
  }
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      minUL[board[i][j]] = min(minUL[board[i][j]], i + j + 1);
      maxUL[board[i][j]] = max(maxUL[board[i][j]], i + j + 1);
    }
  }
  for (int i = 0; i < R; i++) {
    for (int j = 0; j < C; j++) {
      minUR[board[i][j]] = min(minUR[board[i][j]], i + C - j);
      maxUR[board[i][j]] = max(maxUR[board[i][j]], i + C - j);
    }
  }
  for (int i = 1; i <= K; i++)
    for (int j = 1; j <= K; j++) dist[i][j] = cal(i, j);
  int maxx = 0;
  for (int i = 0; i < S - 1; i++) maxx = max(maxx, dist[fret[i]][fret[i + 1]]);
  printf("%d\n", maxx);
  return 0;
}
