#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;
long long readInt() {
  bool minus1 = false;
  long long result = 0;
  char ch;
  ch = getchar();
  while (true) {
    if (ch == '-') break;
    if (ch >= '0' && ch <= '9') break;
    ch = getchar();
  }
  if (ch == '-')
    minus1 = true;
  else
    result = ch - '0';
  while (true) {
    ch = getchar();
    if (ch < '0' || ch > '9') break;
    result = result * 10 + (ch - '0');
  }
  if (minus1)
    return -result;
  else
    return result;
}
const int N = 2222;
int a[N][N];
int kek[MAXN];
int mx_plus[11];
int mn_plus[11];
int mx_minus[11];
int mn_minus[11];
int get(int x, int y) {
  int res = 0;
  res = max(res, mx_plus[x] - mn_plus[y]);
  res = max(res, mx_minus[x] - mn_minus[y]);
  res = max(res, mx_plus[y] - mn_plus[x]);
  res = max(res, mx_minus[y] - mn_minus[x]);
  return res;
}
int main() {
  int n = readInt(), m = readInt(), k = readInt(), second = readInt();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j] = readInt();
    }
  }
  for (int i = 1; i <= k; i++) {
    mx_plus[i] = -MOD;
    mx_minus[i] = -MOD;
    mn_plus[i] = MOD;
    mn_minus[i] = MOD;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      mx_plus[a[i][j]] = max(mx_plus[a[i][j]], i + j);
      mx_minus[a[i][j]] = max(mx_minus[a[i][j]], i - j);
      mn_plus[a[i][j]] = min(mn_plus[a[i][j]], i + j);
      mn_minus[a[i][j]] = min(mn_minus[a[i][j]], i - j);
    }
  }
  int ans = 0;
  for (int i = 1; i <= second; i++) {
    kek[i] = readInt();
    if (i >= 2) {
      ans = max(ans, get(kek[i - 1], kek[i]));
    }
  }
  cout << ans;
  return 0;
}
