#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
pair<int, int> pts[10][MAXN];
int d[10][10];
int S[100005];
inline int ab(int a) { return a < 0 ? -a : a; }
int main() {
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < MAXN; j++)
      pts[i][j].first = 1 << 30, pts[i][j].second = -1;
  int n, m, k, s;
  cin >> n >> m >> k >> s;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int ai;
      cin >> ai;
      pts[ai][i].first = min(pts[ai][i].first, j);
      pts[ai][i].second = max(pts[ai][i].second, j);
    }
  for (int i = 1; i < 10; i++)
    for (int j = i; j < 10; j++) {
      for (int xx = 0; xx < n; xx++) {
        for (int xxx = 0; xxx < n; xxx++) {
          if (pts[i][xx].second == -1 || pts[j][xxx].second == -1) continue;
          d[i][j] =
              max(d[i][j], ab(xx - xxx) +
                               max(ab(pts[i][xx].first - pts[j][xxx].second),
                                   ab(pts[i][xx].second - pts[j][xxx].first)));
        }
      }
      d[j][i] = d[i][j];
    }
  for (int i = 0; i < s; i++) cin >> S[i];
  int maxVal = 0;
  for (int i = 1; i < s; i++) maxVal = max(maxVal, d[S[i]][S[i - 1]]);
  cout << maxVal << '\n';
  return 0;
}
