#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const double PI = 4 * atan(1);
long long int pow(long long int b, long long int p) {
  return !p ? 1
            : pow(b * b % (long long int)(1e9 + 9), p / 2) * (p & 1 ? b : 1) %
                  (long long int)(1e9 + 9);
}
long long int inv(long long int b) {
  return pow(b, (long long int)(1e9 + 9) - 2);
}
void solve() {
  long long int n, m, k, s;
  cin >> n >> m >> k >> s;
  long long int f[10][4];
  for (long long int i = 0; i < 10; ++i) {
    f[i][0] = INT_MIN;
    f[i][1] = INT_MIN;
    f[i][2] = INT_MIN;
    f[i][3] = INT_MIN;
  }
  for (long long int i = 0; i < n; ++i) {
    for (long long int j = 0; j < m; j++) {
      long long int x1;
      cin >> x1;
      f[x1][0] = max(f[x1][0], i + j);
      f[x1][1] = max(f[x1][1], -i - j);
      f[x1][2] = max(f[x1][2], i - j);
      f[x1][3] = max(f[x1][3], j - i);
    }
  }
  long long int x, y, ans = 0;
  cin >> x;
  for (long long int i = 0; i < s - 1; ++i) {
    cin >> y;
    ans = max(ans, max(f[x][3] + f[y][2],
                       max(f[x][2] + f[y][3],
                           max(f[x][0] + f[y][1], f[x][1] + f[y][0]))));
    x = y;
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
