#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, s, i, j, ans[10][5] = {0}, ret = -9999, p, q, pp;
  bool b[10][10] = {0};
  cin >> n >> m >> k >> s;
  memset(ans, 999, sizeof(ans));
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      scanf("%d", &pp);
      if (i + j > ans[pp][1]) ans[pp][1] = i + j;
      if (i - j > ans[pp][2]) ans[pp][2] = i - j;
      if ((-i + j) > ans[pp][3]) ans[pp][3] = -i + j;
      if ((-i - j) > ans[pp][4]) ans[pp][4] = -i - j;
    }
  for (i = 1; i <= s; i++) {
    scanf("%d", &q);
    if (i >= 2 && b[p][q] != 1) {
      for (j = 1; j <= 4; j++) ret = max(ret, (ans[q][j] + ans[p][5 - j]));
      b[p][q] = 1;
      b[q][p] = 1;
    }
    p = q;
  }
  cout << ret;
}
