#include <bits/stdc++.h>
using namespace std;
int n, m, k, s, a, ex[9][4], c, p, res = 0, INF = 999999999;
int main() {
  cin >> n >> m >> k >> s;
  for (int i = 0; i < 9; i++) {
    ex[i][0] = -INF;
    ex[i][1] = INF;
    ex[i][2] = -INF;
    ex[i][3] = INF;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a;
      a--;
      ex[a][0] = max(ex[a][0], i + j);
      ex[a][1] = min(ex[a][1], i + j);
      ex[a][2] = max(ex[a][2], i - j);
      ex[a][3] = min(ex[a][3], i - j);
    }
  }
  cin >> p;
  p--;
  for (int i = 1; i < s; i++) {
    cin >> c;
    c--;
    res = max(res, max(max(ex[p][0] - ex[c][1], ex[c][0] - ex[p][1]),
                       max(ex[p][2] - ex[c][3], ex[c][2] - ex[p][3])));
    p = c;
  }
  cout << res;
}
