#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
int f[10][4];
int g[10][10];
int n, m, k, s;
int TestNum;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> k >> s;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 4; j++) {
      f[i][j] = -0x1f1f1f1f;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int t;
      cin >> t;
      for (int l = 0; l < 4; l++) {
        int ff = (l & 1 ? -1 : 1) * i + (l & 2 ? -1 : 1) * j;
        f[t][l] = max(f[t][l], ff);
      }
    }
  }
  for (int t1 = 1; t1 <= k; t1++) {
    for (int t2 = 1; t2 <= k; t2++) {
      for (int l1 = 0; l1 < 4; l1++) {
        for (int l2 = 0; l2 < 4; l2++) {
          if (l1 + l2 == 3) {
            g[t1][t2] = max(g[t1][t2], f[t1][l1] + f[t2][l2]);
          }
        }
      }
    }
  }
  int x;
  int ans = 0;
  for (int i = 0; i < s; i++) {
    int y = x;
    cin >> x;
    if (i == 0) continue;
    ans = max(ans, g[x][y]);
  }
  cout << ans << endl;
}
