#include <bits/stdc++.h>
using namespace std;
const int OO = 1E9;
vector<int> mpn(10, -OO), mpp(10, -OO), mnp(10, -OO), mnn(10, -OO);
int main() {
  int n, m, k, s, x, y;
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%d", &x);
      mpp[x] = max(mpp[x], i + j);
      mpn[x] = max(mpn[x], i - j);
      mnp[x] = max(mnp[x], -i + j);
      mnn[x] = max(mnn[x], -i - j);
    }
  scanf("%d", &x);
  int ans = 0;
  for (int i = 1; i < s; i++) {
    scanf("%d", &y);
    ans = max(ans, mpp[x] + mnn[y]);
    ans = max(ans, mpn[x] + mnp[y]);
    ans = max(ans, mnp[x] + mpn[y]);
    ans = max(ans, mnn[x] + mpp[y]);
    x = y;
  }
  printf("%d", ans);
  return 0;
}
