#include <bits/stdc++.h>
using namespace std;
const int N = 2000, K = 9, S = 1e5;
int a[N][N], rear[N][K][2], note[S], dist[K][K], m, n, k, s;
void enter() {
  cin >> m >> n >> k >> s;
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < n; ++j) cin >> a[i][j], --a[i][j];
  for (int i = 0; i < s; ++i) cin >> note[i], --note[i];
}
void calcRear() {
  memset(rear, -1, sizeof rear);
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < k; ++j) {
      for (int y = 0; y < n; ++y)
        if (a[i][y] == j) {
          rear[i][j][0] = y;
          break;
        }
      for (int y = n - 1; y >= 0; --y)
        if (a[i][y] == j) {
          rear[i][j][1] = y;
          break;
        }
    }
}
void calcDistance() {
  for (int t1 = 0; t1 < k; ++t1)
    for (int t2 = t1; t2 < k; ++t2) {
      for (int r1 = 0; r1 < m; ++r1)
        for (int r2 = 0; r2 < m; ++r2)
          for (int d1 = 0; d1 < 2; ++d1)
            if (rear[r1][t1][d1] != -1 && rear[r2][t2][d1 ^ 1] != -1)
              dist[t1][t2] = max(
                  dist[t1][t2],
                  abs(r1 - r2) + abs(rear[r1][t1][d1] - rear[r2][t2][d1 ^ 1]));
      dist[t2][t1] = dist[t1][t2];
    }
}
void solve() {
  int res = 0;
  for (int i = 1; i < s; ++i) res = max(res, dist[note[i - 1]][note[i]]);
  cout << res << endl;
}
int main() {
  ios::sync_with_stdio(false);
  enter();
  calcRear();
  calcDistance();
  solve();
  return 0;
}
