#include <bits/stdc++.h>
using namespace std;
bool us[10][10];
int dis[10][10];
vector<int> pl[10];
vector<int> mi[10];
int n, m, k, s;
int calc(int x, int y) {
  int res = 0;
  res = pl[y][pl[y].size() - 1] - pl[x][0];
  res = max(res, mi[y][mi[y].size() - 1] - pl[x][0]);
  res = max(res, mi[x][mi[x].size() - 1] - mi[y][0]);
  res = max(res, pl[x][mi[x].size() - 1] - pl[y][0]);
  return res;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int x;
      scanf("%d", &x);
      pl[x].push_back(i + j);
      mi[x].push_back(i - j);
    }
  for (int i = 1; i < 10; i++) {
    sort(pl[i].begin(), pl[i].end());
    sort(mi[i].begin(), mi[i].end());
  }
  int fi;
  scanf("%d", &fi);
  for (int i = 2; i <= s; i++) {
    int t;
    scanf("%d", &t);
    us[fi][t] = 1;
    us[t][fi] = 1;
    fi = t;
  }
  int ans = 0;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= k; j++)
      if (us[i][j]) {
        ans = max(calc(i, j), ans);
      }
  printf("%d\n", ans);
  return 0;
}
