#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int maxn = 2e5 + 5;
long long int maxnn = 1e18;
double pie = 3.1415926535;
long long int dp[10][10], b[maxn];
long long int ans1[10], ans2[10], ans11[10], ans22[10];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, k, s, x, ans = 0, i, j;
  cin >> n >> m >> k >> s;
  for (i = 1; i <= k; i++) {
    ans1[i] = -mod;
    ans2[i] = -mod;
    ans11[i] = mod;
    ans22[i] = mod;
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cin >> x;
      ans1[x] = max(ans1[x], i + j);
      ans2[x] = max(ans2[x], i - j);
      ans11[x] = min(ans11[x], i + j);
      ans22[x] = min(ans22[x], i - j);
    }
  }
  for (i = 1; i <= k; i++) {
    for (j = 1; j <= k; j++) {
      dp[i][j] = max(dp[i][j], ans1[i] - ans11[j]);
      dp[i][j] = max(dp[i][j], ans2[i] - ans22[j]);
      dp[i][j] = max(dp[i][j], ans1[j] - ans11[i]);
      dp[i][j] = max(dp[i][j], ans2[j] - ans22[i]);
    }
  }
  for (i = 1; i <= s; i++) {
    cin >> b[i];
  }
  for (i = 2; i <= s; i++) {
    ans = max(ans, dp[b[i]][b[i - 1]]);
  }
  cout << ans << endl;
}
