public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		while ((line = in.readLine()) != null && line.length() != 0) {
			int[] MN = readInts(line);
			m = new char[MN[0]][MN[1]];
			char[] curLine;
			for (int i = 0; i < MN[0]; i++) {
				curLine = in.readLine().toCharArray();
				System.arraycopy(curLine, 0, m[i], 0, curLine.length);
			}
			int[] XY = readInts(in.readLine());
			t = m[XY[0]][XY[1]];
			floodFill(XY[0], XY[1], '*', '*');
			m[XY[0]][XY[1]] = '`';
			int max = 0;
			for (int i = 0; i < MN[0]; i++)
				for (int j = 0; j < MN[1]; j++)
					if (m[i][j] == t) {
						curSize = 0;
						floodFill(i, j, '*', '*');
						max = Math.max(max, curSize);
					}
			out.append(max + "\n");
			in.readLine();
		}
		System.out.print(out);
	}