#include <bits/stdc++.h>
using namespace std;
int m1[10][2], m2[10][2];
int main() {
  int n, m, k, s;
  cin >> n >> m >> k >> s;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 2; ++j) {
      m1[i][j] = -1;
      m2[i][j] = 1000000000;
    }
  }
  for (int i = 1; i < n + 1; ++i) {
    for (int j = 1; j < m + 1; ++j) {
      int x;
      cin >> x;
      m1[x][0] = max(m1[x][0], i + j);
      m1[x][1] = max(m1[x][1], i - j);
      m2[x][0] = min(m2[x][0], i + j);
      m2[x][1] = min(m2[x][1], i - j);
    }
  }
  int answer = 0;
  int p, q;
  cin >> p;
  for (int i = 1; i < s; ++i) {
    cin >> q;
    int curr = max(m1[p][0] - m2[q][0], m1[p][1] - m2[q][1]);
    int curr1 = max(m1[q][0] - m2[p][0], m1[q][1] - m2[p][1]);
    answer = max(curr1, max(answer, curr));
    p = q;
  }
  cout << answer << endl;
  return 0;
}
