#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 main(int argc, const char* argv[]) {
  cin >> N >> M >> K >> S;
  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));
    }
  for (int i = 0; i < S; i++) cin >> s[i];
  for (int k = 1; k <= K; k++) {
    int sumMax = INT_MIN, sumMin = INT_MAX, diffMax = INT_MIN,
        diffMin = INT_MAX;
    for (pair<int, int> p : A[k]) {
      int sum = p.first + p.second, diff = p.first - p.second;
      sumMax = max(sumMax, sum);
      sumMin = min(sumMin, sum);
      diffMax = max(diffMax, diff);
      diffMin = min(diffMin, diff);
    }
    extreme[k][0] = sumMax;
    extreme[k][1] = sumMin;
    extreme[k][2] = diffMax;
    extreme[k][3] = diffMin;
  }
  for (int i = 1; i <= K; i++)
    for (int j = 1; j <= K; j++) {
      m[i][j] =
          max(extreme[i][0] - extreme[j][1], extreme[i][2] - extreme[j][3]);
      m[i][j] = max(m[i][j], -extreme[i][3] + extreme[j][2]);
      m[i][j] = max(m[i][j], -extreme[i][1] + extreme[j][0]);
    }
  int ANS = 0;
  for (int i = 1; i < S; i++) ANS = max(ANS, m[s[i - 1]][s[i]]);
  cout << ANS << endl;
  return 0;
}
