#include <bits/stdc++.h>
#pragma comment(linker, "/stack:256000000")
using namespace std;
const int INF = (int)1e9;
int mnx[11], mxx[11], mny[11], mxy[11];
int main() {
  int n, m, k, s, x;
  cin >> n >> m >> k >> s;
  for (int(i) = 0; (i) < (11); (i)++) mnx[i] = mny[i] = INF;
  for (int(i) = 0; (i) < (11); (i)++) mxx[i] = mxy[i] = -INF;
  for (int(i) = 0; (i) < (n); (i)++) {
    for (int(j) = 0; (j) < (m); (j)++) {
      cin >> x;
      mnx[x] = min(mnx[x], i + j);
      mxx[x] = max(mxx[x], i + j);
      mny[x] = min(mny[x], i - j);
      mxy[x] = max(mxy[x], i - j);
    }
  }
  int p, res = 0;
  cin >> p;
  for (int(i) = 0; (i) < (s - 1); (i)++) {
    cin >> x;
    res = max(res, abs(mxx[x] - mnx[p]));
    res = max(res, abs(mxx[p] - mnx[x]));
    res = max(res, abs(mxy[x] - mny[p]));
    res = max(res, abs(mxy[p] - mny[x]));
    p = x;
  }
  cout << res << endl;
  return 0;
}
