#include <bits/stdc++.h>
using namespace std;
int i, j, k;
int main() {
  int T = 1;
  for (k = 0; k < T; k++) {
    int n;
    scanf("%d", &n);
    int m;
    scanf("%d", &m);
    int l;
    scanf("%d", &l);
    int s;
    scanf("%d", &s);
    vector<vector<int> > nt1(l + 1);
    vector<vector<int> > nt2(l + 1);
    int temp;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        cin >> temp;
        nt1[temp].push_back(i + j);
        nt2[temp].push_back(i - j);
      }
    }
    for (i = 1; i < l + 1; i++) {
      sort((nt1[i]).begin(), (nt1[i]).end());
      sort((nt2[i]).begin(), (nt2[i]).end());
    }
    bool pn[l + 1][l + 1];
    for (i = 0; i < l + 1; i++)
      for (j = 0; j < l + 1; j++) pn[i][j] = false;
    cin >> temp;
    int temp2;
    for (i = 1; i < s; i++) {
      cin >> temp2;
      pn[temp][temp2] = true;
      pn[temp2][temp] = true;
      temp = temp2;
    }
    int mt = 0;
    for (i = 0; i < l + 1; i++) {
      for (j = 0; j < l + 1; j++) {
        if (pn[i][j]) {
          int l1 = nt1[i].size();
          int l2 = nt2[i].size();
          mt = max(mt, nt1[i][l1 - 1] - nt1[j][0]);
          mt = max(mt, nt2[i][l2 - 1] - nt2[j][0]);
        }
      }
    }
    cout << mt << endl;
  }
  return 0;
}
