#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 100, OO = 1e8, M = 3e6 + 1000, P = 6151, sq = 1e3, lg = 60;
vector<pair<int, int> > v[N];
vector<pair<int, pair<int, int> > > g[N];
int dp[N][N];
inline int mx(int x, int y) {
  if (x > y)
    return x;
  else
    return y;
}
inline int asb(int x) {
  if (x > 0)
    return x;
  else
    return -x;
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m, k, s;
  cin >> n >> m >> k >> s;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x;
      cin >> x;
      v[x].push_back({i, j});
    }
  }
  for (int i = 1; i <= 9; i++) {
    sort(v[i].begin(), v[i].end());
    if (v[i].empty()) continue;
    g[i].push_back({v[i][0].first, {v[i][0].second, v[i][0].second}});
    for (int j = 1; j < (int)v[i].size(); j++) {
      if (v[i][j].first == v[i][j - 1].first)
        g[i][(int)g[i].size() - 1].second.second = v[i][j].second;
      else
        g[i].push_back({v[i][j].first, {v[i][j].second, v[i][j].second}});
    }
  }
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      for (auto u : g[i]) {
        for (int l = (int)g[j].size() - 1; l >= 0; l--) {
          pair<int, pair<int, int> > h = g[j][l];
          if (h.first < u.first) break;
          dp[i][j] =
              mx(dp[i][j], asb(u.first - h.first) +
                               mx(mx(asb(u.second.first - h.second.first),
                                     asb(u.second.first - h.second.second)),
                                  mx(asb(u.second.second - h.second.first),
                                     asb(u.second.second - h.second.second))));
        }
      }
    }
  }
  for (int i = 1; i <= 9; i++)
    for (int j = 1; j <= 9; j++) dp[i][j] = mx(dp[j][i], dp[i][j]);
  int x, y, ans = 0;
  cin >> x;
  for (int i = 1; i < s; i++) {
    cin >> y;
    ans = mx(ans, dp[x][y]);
    x = y;
  }
  cout << ans << endl;
  return 0;
}
