#include <bits/stdc++.h>
using namespace std;
int ar[20][4], sn[200000];
int main() {
  for (int i = 0; i < 10; i++) {
    ar[i][0] = ar[i][1] = ar[i][2] = ar[i][3] = -200000000;
  }
  int n, m, k, s;
  cin >> n >> m >> k >> s;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int vl;
      scanf("%d", &vl);
      ar[vl][0] = max(ar[vl][0], i + j);
      ar[vl][1] = max(ar[vl][1], i - j);
      ar[vl][2] = max(ar[vl][2], j - i);
      ar[vl][3] = max(ar[vl][3], -i - j);
    }
  int ans = 0;
  for (int i = 0; i < s; i++) scanf("%d", &sn[i]);
  for (int i = 1; i < s; i++) {
    int tmp = 0;
    tmp = max(tmp, ar[sn[i - 1]][0] + ar[sn[i]][3]);
    tmp = max(tmp, ar[sn[i - 1]][1] + ar[sn[i]][2]);
    tmp = max(tmp, ar[sn[i - 1]][2] + ar[sn[i]][1]);
    tmp = max(tmp, ar[sn[i - 1]][3] + ar[sn[i]][0]);
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}
