#include <bits/stdc++.h>
using namespace std;
const int N = int(2e3 + 5);
int a[N][N], mx[10][10];
vector<pair<int, pair<int, int>>> v[10];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k, q, f;
  cin >> n >> m >> k >> q;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      if (v[a[i][j]].empty() || v[a[i][j]].back().first != i) {
        v[a[i][j]].emplace_back(i, make_pair(j, j));
      } else {
        v[a[i][j]].back().second.second = j;
      }
    }
  }
  for (int i = 1; i <= k; i++) {
    for (int j = i; j <= k; j++) {
      for (auto ii : v[i]) {
        for (auto jj : v[j]) {
          mx[i][j] =
              max(mx[i][j], abs(ii.first - jj.first) +
                                max(abs(ii.second.first - jj.second.second),
                                    abs(ii.second.second - jj.second.first)));
        }
      }
      mx[j][i] = mx[i][j];
    }
  }
  int ans = 0;
  cin >> f;
  for (int i = 1; i < q; i++) {
    int s;
    cin >> s;
    ans = max(ans, mx[f][s]);
    f = s;
  }
  cout << ans << "\n";
  return 0;
}
