#include <bits/stdc++.h>
using namespace std;
int N, M, K, S, n;
int s[100005];
vector<pair<int, int> > A[10];
int extreme[10][4];
int m[10][10];
int minS[10], maxS[10], minD[10], maxD[10];
int main(int argc, const char* argv[]) {
  cin >> N >> M >> K >> S;
  for (int i = 0; i < 10; i++) {
    minS[i] = INT_MAX;
    maxS[i] = INT_MIN;
    minD[i] = INT_MAX;
    maxD[i] = INT_MIN;
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) {
      cin >> n;
      A[n].push_back(pair<int, int>(i, j));
      minS[n] = min(minS[n], i + j);
      maxS[n] = max(maxS[n], i + j);
      minD[n] = min(minD[n], i - j);
      maxD[n] = max(maxD[n], i - j);
    }
  for (int i = 0; i < S; i++) cin >> s[i];
  for (int i = 1; i <= K; i++)
    for (int j = 1; j <= K; j++) {
      m[i][j] = max(maxS[i] - minS[j], maxD[i] - minD[j]);
      m[i][j] = max(m[i][j], -minD[i] + maxD[j]);
      m[i][j] = max(m[i][j], -minS[i] + maxS[j]);
    }
  int ANS = 0;
  for (int i = 1; i < S; i++) ANS = max(ANS, m[s[i - 1]][s[i]]);
  cout << ANS << endl;
  return 0;
}
