#include <iostream>
using namespace std;

int N;
int ans = INT_MAX;
bool visited[55] = {};
int ticket[55][55] = {};

void dfs(int s, int t, int cost)
{
	if(s == t) {
		ans = min(ans, cost);
		return;
	}
	visited[s] = true;
	for(int i=0; i<N; i++) {
		if(ticket[s][i] != -1 && !visited[i]){
			visited[i] = true;
			int tmp = cost + ticket[s][i];
			if(cost > 0) tmp -= 50;
			dfs(i, t, tmp);
			visited[i] = false;
		}
	}
}

int main()
{
	cin >> N;
	for(int i=0; i<N; i++) {
		for(int j=0; j<N; j++) {
			cin >> ticket[i][j];
		}
	}
	int src, trg;
	cin >> src >> trg;
	dfs(src-1, trg-1, 0);
	cout << ans << endl;
}
