#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int n, m, k, s, a[N][N], b[100010], dis[11][11];
int mx[4][11];
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  memset(mx, 0x80, sizeof(mx));
  memset(dis, 0x80, sizeof(dis));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      mx[0][a[i][j]] = max(mx[0][a[i][j]], i + j);
      mx[1][a[i][j]] = max(mx[1][a[i][j]], i - j);
      mx[2][a[i][j]] = max(mx[2][a[i][j]], -i + j);
      mx[3][a[i][j]] = max(mx[3][a[i][j]], -i - j);
    }
  for (int i = 1; i <= s; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      for (int x = 1; x <= k; x++) {
        dis[a[i][j]][x] = max(dis[a[i][j]][x], i + j + mx[3][x]);
        dis[a[i][j]][x] = max(dis[a[i][j]][x], i - j + mx[2][x]);
        dis[a[i][j]][x] = max(dis[a[i][j]][x], -i + j + mx[1][x]);
        dis[a[i][j]][x] = max(dis[a[i][j]][x], -i - j + mx[0][x]);
      }
    }
  int ret = 0;
  for (int i = 2; i <= s; i++) ret = max(ret, dis[b[i - 1]][b[i]]);
  cout << ret << endl;
  return 0;
}
