Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the string. When Dima pulls the i-th string holding it on the j-th fret the guitar produces a note, let's denote it as aij. We know that Dima's guitar can produce k distinct notes. It is possible that some notes can be produced in multiple ways. In other words, it is possible that aij = apq at (i, j) ≠ (p, q).

Dima has already written a song — a sequence of s notes. In order to play the song, you need to consecutively produce the notes from the song on the guitar. You can produce each note in any available way. Dima understood that there are many ways to play a song and he wants to play it so as to make the song look as complicated as possible (try to act like Cobein).

We'll represent a way to play a song as a sequence of pairs (xi, yi) (1 ≤ i ≤ s), such that the xi-th string on the yi-th fret produces the i-th note from the song. The complexity of moving between pairs (x1, y1) and (x2, y2) equals <image> + <image>. The complexity of a way to play a song is the maximum of complexities of moving between adjacent pairs.

Help Dima determine the maximum complexity of the way to play his song! The guy's gotta look cool!

Input

The first line of the input contains four integers n, m, k and s (1 ≤ n, m ≤ 2000, 1 ≤ k ≤ 9, 2 ≤ s ≤ 105). 

Then follow n lines, each containing m integers aij (1 ≤ aij ≤ k). The number in the i-th row and the j-th column (aij) means a note that the guitar produces on the i-th string and the j-th fret.

The last line of the input contains s integers qi (1 ≤ qi ≤ k) — the sequence of notes of the song.

Output

In a single line print a single number — the maximum possible complexity of the song.

Examples

Input

4 6 5 7
3 1 2 2 3 1
3 2 2 2 5 5
4 2 2 2 5 3
3 2 2 1 4 3
2 3 1 4 1 5 1


Output

8


Input

4 4 9 5
4 7 9 5
1 2 1 7
8 3 4 9
5 7 7 2
7 1 9 2 5


Output

4
#include <bits/stdc++.h>
using namespace std;
const int MAX_K = 10;
const int INF = 0x3f3f3f3f;
int v[MAX_K][1 << 2];
int comp(int mask) { return ((1 << 2) - 1) ^ mask; }
int solve(int x, int y) {
  int aux = 0;
  for (int mask = 0; mask < 1 << 2; mask++) {
    aux = max(aux, v[x][mask] + v[y][comp(mask)]);
  }
  return aux;
}
int get_val(int i, int j, int mask) {
  if (mask & 1) {
    j *= -1;
  }
  if ((mask >> 1) & 1) {
    i *= -1;
  }
  return i + j;
}
int main(void) {
  int n, m, k, s;
  int x, y;
  for (int i = 0; i < MAX_K; i++) {
    for (int j = 0; j < 1 << 2; j++) {
      v[i][j] = -INF;
    }
  }
  scanf(" %d %d %d %d", &n, &m, &k, &s);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf(" %d", &x);
      for (int mask = 0; mask < 1 << 2; mask++) {
        int aux = get_val(i, j, mask);
        v[x][mask] = max(v[x][mask], aux);
      }
    }
  }
  int res = 0;
  scanf(" %d", &x);
  while (s-- > 1) {
    scanf(" %d", &y);
    res = max(res, solve(x, y));
    x = y;
  }
  printf("%d\n", res);
  return 0;
}
