#include <fstream>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

struct queue
{
	int x;
	int y;
};

deque <queue> open;
bool RouteExist = false;

bool IsMapSide(int &x, int &y, vector <vector <int> > &map)
{
	return (x == 0 || y == 0 || x == map.size() - 1 || y == map[0].size() - 1);
}

void FindRoute(vector <vector <int> > &map, int &route)
{
	while (open.size() != 0)
	{
		route++;
		int k = open.size();
		for (int i = 0; i < k; i++)
		{
			int m = open.back().x;
			int n = open.back().y;
			open.pop_back();
			if (map[m][n] == 0)
			{
				if (IsMapSide(m, n, map))
				{
					RouteExist = true;
					return;
				}
			}
			else
			{
				continue;
			}
			map[m][n] = 1;
			open.push_front(queue{ m - 1, n });
			open.push_front(queue{ m + 1, n });
			open.push_front(queue{ m, n - 1 });
			open.push_front(queue{ m, n + 1 });
		}
	}
}



int main()
{
	ifstream input("DDNNMC.inp");
	ofstream output("DDNNMC.out");
	int m, n;
	int x, y;
	int route = -1;
	input >> m >> n >> x >> y;
	x--;
	y--;
	open.push_back(queue{ x, y });
	vector <vector <int> > map(m, vector <int> (n));
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			input >> map[i][j];
		}
	}
	FindRoute(map, route);
	if (RouteExist)
	{
		output << route;
	}
	else
	{
		output << 0;
	}
	input.close();
	output.close();
	return 0;
}