#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, s;
  scanf("%d %d %d %d", &n, &m, &k, &s);
  vector<vector<int> > a(n, vector<int>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) scanf("%d ", &a[i][j]);
  vector<int> b(s);
  for (int i = 0; i < s; ++i) scanf("%d", &b[i]);
  vector<vector<int> > d(k + 1, vector<int>(k + 1, -1));
  vector<vector<int> > lewo(n, vector<int>(m));
  vector<vector<int> > prawo(n, vector<int>(m));
  vector<vector<int> > gora(n, vector<int>(m));
  vector<vector<int> > dol(n, vector<int>(m));
  for (int i = 1; i <= k; ++i) {
    for (int l = 0; l < n; ++l) {
      lewo[l][0] = -1;
      if (a[l][0] == i) lewo[l][0] = 0;
      for (int o = 1; o < m; ++o) {
        lewo[l][o] = -1;
        if (lewo[l][o - 1] != -1)
          lewo[l][o] = lewo[l][o - 1] + 1;
        else {
          if (a[l][o] == i) lewo[l][o] = 0;
        }
      }
    }
    for (int l = 0; l < n; ++l) {
      prawo[l][m - 1] = -1;
      if (a[l][m - 1] == i) prawo[l][m - 1] = 0;
      for (int o = m - 2; o >= 0; --o) {
        prawo[l][o] = -1;
        if (prawo[l][o + 1] != -1)
          prawo[l][o] = prawo[l][o + 1] + 1;
        else {
          if (a[l][o] == i) prawo[l][o] = 0;
        }
      }
    }
    for (int o = 0; o < m; ++o) {
      gora[0][o] = -1;
      if (max(lewo[0][o], prawo[0][o]) != -1)
        gora[0][o] = max(lewo[0][o], prawo[0][o]);
      for (int l = 1; l < n; ++l) {
        gora[l][o] = -1;
        if (gora[l - 1][o] != -1) gora[l][o] = gora[l - 1][o] + 1;
        gora[l][o] = max(gora[l][o], max(lewo[l][o], prawo[l][o]));
      }
    }
    for (int o = 0; o < m; ++o) {
      dol[n - 1][o] = -1;
      if (max(lewo[n - 1][o], prawo[n - 1][o]) != -1)
        dol[n - 1][o] = max(lewo[n - 1][o], prawo[n - 1][o]);
      for (int l = n - 2; l >= 0; --l) {
        dol[l][o] = -1;
        if (dol[l + 1][o] != -1) dol[l][o] = dol[l + 1][o] + 1;
        dol[l][o] = max(dol[l][o], max(lewo[l][o], prawo[l][o]));
      }
    }
    for (int l = 0; l < n; ++l)
      for (int o = 0; o < m; ++o)
        d[a[l][o]][i] = max(d[a[l][o]][i], max(gora[l][o], dol[l][o]));
  }
  int odp = -1;
  for (int i = 0; i <= s - 2; ++i) odp = max(odp, d[b[i]][b[i + 1]]);
  printf("%d", odp);
  return 0;
}
