#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, k, s;
  cin >> n >> m >> k >> s;
  vector<vector<int>> at(2 * k + 1);
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      at[a[i][j]].push_back(i + j);
      at[a[i][j] + k].push_back(i - j);
    }
  }
  for (int i = 1; i <= 2 * k; i++) {
    sort(at[i].begin(), at[i].end());
  }
  int res = 0;
  vector<int> q(s);
  for (int& x : q) cin >> x;
  for (int i = 0; i < s - 1; i++) {
    int x = q[i], y = q[i + 1];
    for (int j = 0; j < 2; j++, swap(x, y)) {
      res = max(res, at[x + j * k].back() - at[y + j * k].front());
      res = max(res, at[y + j * k].back() - at[x + j * k].front());
    }
  }
  cout << res << '\n';
}
