#include <bits/stdc++.h>
using namespace std;
void SieveOfErat() {
  bool prime[1000001];
  memset(prime, true, sizeof(prime));
  for (long long vec = 2; vec * vec <= 1000000; vec++) {
    if (prime[vec] == true) {
      for (long long dd = vec * 2; dd <= 1000000; dd += vec) prime[dd] = false;
    }
  }
}
long long gcd(long long aa, long long id2) {
  if (aa == 0) {
    return id2;
  } else
    return gcd(aa % id2, id2);
}
struct vect {
  struct vect *foll;
  long long calc;
  struct vect *succ;
};
int a[5001][5001], dp[20][20];
int mark[20][5001][2], b[500001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, s, l;
  int ans = 0, val;
  cin >> n >> m >> l >> s;
  memset(mark, -1, sizeof(mark));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (mark[a[i][j]][i][0] == -1) mark[a[i][j]][i][0] = j;
      if (mark[a[i][j]][i][1] == -1)
        mark[a[i][j]][i][1] = j;
      else {
        mark[a[i][j]][i][0] = min(mark[a[i][j]][i][0], j);
        mark[a[i][j]][i][1] = max(mark[a[i][j]][i][1], j);
      }
    }
  }
  for (int i = 0; i < s; i++) cin >> b[i];
  for (int i = 1; i < s; i++) {
    if (dp[b[i]][b[i - 1]] != 0) continue;
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        val = 0;
        if (mark[b[i]][j][0] == -1) break;
        if (mark[b[i - 1]][k][0] == -1)
          continue;
        else {
          val = abs(mark[b[i]][j][0] - mark[b[i - 1]][k][0]);
          val = max(val, abs(mark[b[i]][j][0] - mark[b[i - 1]][k][1]));
          val = max(val, abs(mark[b[i]][j][1] - mark[b[i - 1]][k][0]));
          dp[b[i]][b[i - 1]] = max(dp[b[i]][b[i - 1]], val + abs(j - k));
          dp[b[i - 1]][b[i]] = dp[b[i]][b[i - 1]];
        }
      }
    }
    ans = max(ans, dp[b[i]][b[i - 1]]);
  }
  cout << ans << endl;
  return 0;
}
