#include <bits/stdc++.h>
using namespace std;
int a[10][5];
int main() {
  int n, m, k, s, x, y;
  cin >> n >> m >> k >> s;
  memset(a, 250, sizeof(a));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &x);
      a[x][0] = max(a[x][0], -i - j);
      a[x][1] = max(a[x][1], -i + j);
      a[x][2] = max(a[x][2], i - j);
      a[x][3] = max(a[x][3], i + j);
    }
  int ans = -100000000;
  cin >> x;
  for (int i = 2; i <= s; i++) {
    cin >> y;
    for (int j = 0; j <= 3; j++) ans = max(ans, a[x][j] + a[y][3 - j]);
    x = y;
  }
  cout << ans;
  return 0;
}
