#include <bits/stdc++.h>
using namespace std;
int n, m, k, s;
int a[2002][2002];
int b[100005];
inline int f(int x) { return x > 0 ? x : -x; }
int Map[2002][2002];
int l[2002][11], r[2002][11];
int main() {
  ios::sync_with_stdio(false);
  int i, j, u, v;
  cin >> n >> m >> k >> s;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) cin >> a[i][j];
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++)
      if (!l[i][a[i][j]]) l[i][a[i][j]] = j + 1;
    for (j = m - 1; j >= 0; j--)
      if (!r[i][a[i][j]]) r[i][a[i][j]] = j + 1;
  }
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++)
      for (u = 1; u <= k; u++)
        for (v = 1; v <= k; v++) {
          int &ret = Map[u][v];
          if (r[i][u] && l[j][v])
            ret = max(ret, f(r[i][u] - l[j][v]) + (j - i));
          if (l[i][u] && r[j][v])
            ret = max(ret, f(l[i][u] - r[j][v]) + (j - i));
          Map[v][u] = ret;
        }
  for (i = 0; i < s; i++) cin >> b[i];
  int ans = 0;
  for (i = 1; i < s; i++) ans = max(ans, Map[b[i - 1]][b[i]]);
  cout << ans << endl;
  return 0;
}
