#include <bits/stdc++.h>
using namespace std;
int ag[9][2], cg[9][2];
int main() {
  std::ios::sync_with_stdio(false);
  int n, m, k, s, t, t2, ans = 0;
  cin >> n >> m >> k >> s;
  memset(cg, 0x3f3f3f3f, sizeof(cg));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> t;
      ag[t - 1][0] = max(ag[t - 1][0], i + 1 + j + 1);
      cg[t - 1][0] = min(cg[t - 1][0], i + 1 + j + 1);
      ag[t - 1][1] = max(ag[t - 1][1], i - j);
      cg[t - 1][1] = min(cg[t - 1][1], i - j);
    }
  cin >> t;
  for (int i = 1; i < s; i++) {
    cin >> t2;
    ans = max(ans, ag[t - 1][0] - cg[t2 - 1][0]);
    ans = max(ans, ag[t2 - 1][0] - cg[t - 1][0]);
    ans = max(ans, ag[t - 1][1] - cg[t2 - 1][1]);
    ans = max(ans, ag[t2 - 1][1] - cg[t - 1][1]);
    t = t2;
  }
  cout << ans << endl;
  return 0;
}
