#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000,100000000000")
using namespace std;
const long long inf = 1e18 + 7;
const long long mod = 1e9 + 7;
const double eps = 1e-12;
const double PI = 2 * acos(0.0);
const double E = 2.71828;
int n, m, k, s;
int f[15][15];
int main(void) {
  scanf("%d%d%d%d", &n, &m, &k, &s);
  for (long long(i) = 0; (i) < (long long)(15); (i)++) {
    f[0][i] = f[2][i] = -mod;
    f[1][i] = f[3][i] = mod;
  }
  for (long long(i) = 0; (i) < (long long)(n); (i)++) {
    for (long long(j) = 0; (j) < (long long)(m); (j)++) {
      int cur;
      scanf("%d", &cur);
      f[0][cur] = max(f[0][cur], (int)i + (int)j);
      f[1][cur] = min(f[1][cur], (int)i + (int)j);
      f[2][cur] = max(f[2][cur], (int)i - (int)j);
      f[3][cur] = min(f[3][cur], (int)i - (int)j);
    }
  }
  int res = 0;
  int prev = 0;
  for (long long(i) = 0; (i) < (long long)(s); (i)++) {
    int cur;
    scanf("%d", &cur);
    if (!i) {
      prev = cur;
      continue;
    }
    res = max(res, f[0][cur] - f[1][prev]);
    res = max(res, f[0][prev] - f[1][cur]);
    res = max(res, f[2][cur] - f[3][prev]);
    res = max(res, f[2][prev] - f[3][cur]);
    prev = cur;
  }
  cout << res << endl;
  return 0;
}
