#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m, k, s;
  cin >> n >> m >> k >> s;
  int a[n][m];
  vector<pair<int, int> > v[k];
  for (int i = 0; i < n; ++i) {
    int chk[k];
    memset(chk, 0, sizeof(chk));
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (!chk[a[i][j] - 1]) v[a[i][j] - 1].push_back(make_pair(i, j));
      chk[a[i][j] - 1] = 1;
    }
    memset(chk, 0, sizeof(chk));
    for (int j = m - 1; j >= 0; j--) {
      if (!chk[a[i][j] - 1]) v[a[i][j] - 1].push_back(make_pair(i, j));
      chk[a[i][j] - 1] = 1;
    }
  }
  int q[s];
  for (int i = 0; i < s; ++i) {
    cin >> q[i];
    q[i]--;
  }
  map<pair<int, int>, int> m1;
  for (int i = 0; i < k; i++) {
    for (int j = i; j < k; j++) {
      int ans = 0;
      for (int x1 = 0; x1 < v[i].size(); x1++) {
        for (int y1 = 0; y1 < v[j].size(); y1++) {
          ans = max(ans, abs(v[i][x1].first - v[j][y1].first) +
                             abs(v[i][x1].second - v[j][y1].second));
        }
      }
      m1[make_pair(i, j)] = ans;
    }
  }
  int ans = 0;
  for (int i = 1; i < s; ++i) {
    int a1, b1;
    a1 = min(q[i - 1], q[i]);
    b1 = max(q[i - 1], q[i]);
    ans = max(ans, m1[make_pair(a1, b1)]);
  }
  cout << ans << endl;
}
