#include <bits/stdc++.h>
using namespace std;
int MAXN = 2010;
int INF = 1000000000;
int n, m, k, s;
int main() {
  int mmix[10], mmiy[10];
  int mmax[10], mmay[10];
  for (int i = 0; i < (10); ++i) {
    mmix[i] = INF;
    mmiy[i] = INF;
    mmax[i] = INF;
    mmay[i] = INF;
  }
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      int a;
      scanf("%d", &a);
      if (mmix[a] == INF) mmix[a] = i - j;
      if (mmiy[a] == INF) mmiy[a] = i + j;
      if (mmax[a] == INF) mmax[a] = i - j;
      if (mmay[a] == INF) mmay[a] = j + i;
      mmix[a] = min(mmix[a], i - j);
      mmiy[a] = min(mmiy[a], j + i);
      mmax[a] = max(mmax[a], i - j);
      mmay[a] = max(mmay[a], j + i);
    }
  }
  int res = -1;
  int a, b;
  scanf("%d", &a);
  for (int i = 0; i < (s - 1); ++i) {
    scanf("%d", &b);
    if (mmax[a] != INF && mmix[b] != INF) {
      res = max(res, abs(mmax[a] - mmix[b]));
      res = max(res, abs(mmax[b] - mmix[a]));
      res = max(res, abs(mmay[a] - mmiy[b]));
      res = max(res, abs(mmay[b] - mmiy[a]));
      res = max(res, mmax[a] - mmix[b]);
      res = max(res, mmax[b] - mmix[a]);
      res = max(res, mmay[a] - mmiy[b]);
      res = max(res, mmay[b] - mmiy[a]);
    }
    a = b;
  }
  cout << res << endl;
}
