#include <bits/stdc++.h>
using namespace std;
int xx[4] = {0, 0, 1, -1};
int yy[4] = {1, -1, 0, 0};
int n, m, k, s;
int p[int(1e5) + 100];
int a[int(2e3 + 100)][int(2e3 + 100)], t[15][15], r[10][int(2e3 + 100)],
    l[10][int(2e3 + 100)];
int solve(int c, int d) {
  int res = 0;
  for (int i = (1), _b = (n); i <= _b; i++)
    if (r[c][i] != 0 && l[c][i] != 0)
      for (int j = (1), _b = (n); j <= _b; j++)
        if (r[d][j] != 0 && l[d][j] != 0) {
          res = max(res, abs(r[c][i] - r[d][j]) + abs(i - j));
          res = max(res, abs(r[c][i] - l[d][j]) + abs(i - j));
          res = max(res, abs(l[c][i] - r[d][j]) + abs(i - j));
          res = max(res, abs(l[c][i] - l[d][j]) + abs(i - j));
        }
  return res;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (int i = (1), _b = (n); i <= _b; i++)
    for (int j = (1), _b = (m); j <= _b; j++) {
      scanf("%d", &a[i][j]);
      int c = a[i][j];
      if (l[c][i] == 0)
        l[c][i] = j;
      else
        l[c][i] = min(l[c][i], j);
      r[c][i] = max(r[c][i], j);
    }
  for (int i = (1), _b = (k); i <= _b; i++)
    for (int j = (i), _b = (k); j <= _b; j++) {
      t[i][j] = solve(i, j);
      t[j][i] = t[i][j];
    }
  int res = 0;
  for (int i = (1), _b = (s); i <= _b; i++) {
    scanf("%d", &p[i]);
    if (i >= 2) res = max(res, t[p[i]][p[i - 1]]);
  }
  cout << res << endl;
}
