#include <bits/stdc++.h>
using namespace std;
const int MAX = 1001;
const int INF = 10100000;
int m[4][MAX];
pair<int, int> p[4][MAX];
int ans[MAX][MAX];
int a[MAX][MAX], b[MAX];
int main() {
  int N, M, k, s;
  scanf("%d %d %d %d", &N, &M, &k, &s);
  for (int i = 0; i < int(k + 1); i++)
    m[0][i] = m[2][i] = INF, m[1][i] = m[4][i] = -INF;
  for (int i = 0; i < int(N); i++)
    for (int j = 0; j < int(M); j++) {
      scanf("%d", &a[i][j]);
      int k = a[i][j];
      if (m[0][k] > i - j) m[0][k] = i - j, p[0][k] = make_pair(i, j);
      if (m[1][k] < i - j) m[1][k] = i - j, p[1][k] = make_pair(i, j);
      if (m[2][k] > i + j) m[2][k] = i + j, p[2][k] = make_pair(i, j);
      if (m[3][k] < i + j) m[3][k] = i + j, p[3][k] = make_pair(i, j);
    }
  for (int i = 0; i < int(k + 1); i++)
    if (m[0][i] != INF)
      for (int j = 0; j < int(k + 1); j++)
        if (m[0][j] != INF) {
          for (int a = 0; a < int(4); a++)
            for (int b = 0; b < int(4); b++)
              ans[i][j] =
                  max(ans[i][j], abs(p[a][i].first - p[b][j].first) +
                                     abs(p[a][i].second - p[b][j].second));
        }
  for (int i = 0; i < int(s); i++) scanf("%d", b + i);
  int ANS = 0;
  for (int i = 1; i < s; i++) ANS = max(ANS, ans[b[i - 1]][b[i]]);
  printf("%d\n", ANS);
}
