#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)998244353;
const int N = (int)1e5 + 7;
const double eps = 1e-6;
bool eq(const double &a, const double &b) { return fabs(a - b) < eps; }
bool ls(const double &a, const double &b) { return a + eps < b; }
bool le(const double &a, const double &b) { return eq(a, b) || ls(a, b); }
char read_char() {
  char c;
  for (;;) {
    c = getchar();
    if (c >= 'A' && c <= 'Z') return c;
  }
}
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int add(int a, int b) {
  if ((a += b) >= MOD) a -= MOD;
  return a;
}
int mul(int a, int b) { return 1ll * a * b % MOD; }
int n, m, k, s, a[2007][2007], q[N], num[10][4];
void Init() {
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j) scanf("%d", &a[i][j]);
  for (int i = (0); i < (s); ++i) scanf("%d", &q[i]);
  memset(num, 0x80, sizeof(num));
}
int f(int x) { return x ? -1 : 1; }
int Solve() {
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (m); ++j)
      for (int k = (0); k < (4); ++k) {
        num[a[i][j]][k] =
            max(num[a[i][j]][k], f(k >> 1 & 1) * i + f(k & 1) * j);
      }
  int ans = 0;
  for (int i = (1); i < (s); ++i)
    for (int k = (0); k < (4); ++k) {
      ans = max(ans, num[q[i]][k] + num[q[i - 1]][3 - k]);
    }
  return !printf("%d\n", ans);
}
int main() {
  while (~scanf("%d%d%d%d", &n, &m, &k, &s)) {
    Init();
    Solve();
  }
  return 0;
}
