#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
vector<int> used, dist, par;
vector<vector<pair<int,int> > > g;
int n, inf=1e9;
void dijkstra(int v){
dist[v]=0;
int mn=0;
while(mn!=inf){
used[v]=1;
for(auto [x,y]:g[v]){
if(dist[x]>dist[v]+y){
dist[x]=dist[v]+y;
par[x]=v;
}
}
mn=inf;
for(int i=0;i<n; i++){
if (dist[i]<mn && !used[i]){
mn=dist[i];
v=i;
}
}
}
}
int main() {
int s,f;
cin>>n>>s>>f;
s--;f--;
used.assign(n,0);
dist.assign(n,inf);
par.assign(n,-1);
g.resize(n);
for(int i=0; i<n; i++)
for(int j=0; j<n; j++){
int x;
cin>>x;
if(x!=-1 && i!=j){
g[i].push_back({j,x});
}
}
dijkstra(s);
if(dist[f]==inf) dist[f]=-1;
cout<<dist[f];
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdmVjdG9yPGludD4gdXNlZCwgZGlzdCwgcGFyOwp2ZWN0b3I8dmVjdG9yPHBhaXI8aW50LGludD4gPiA+IGc7CmludCBuLCBpbmY9MWU5Owp2b2lkIGRpamtzdHJhKGludCB2KXsKCWRpc3Rbdl09MDsKCWludCBtbj0wOwoJd2hpbGUobW4hPWluZil7CgkJdXNlZFt2XT0xOwoJCWZvcihhdXRvIFt4LHldOmdbdl0pewoJCQlpZihkaXN0W3hdPmRpc3Rbdl0reSl7CgkJCQlkaXN0W3hdPWRpc3Rbdl0reTsKCQkJCXBhclt4XT12OwoJCQl9CgkJfQoJCW1uPWluZjsKCQlmb3IoaW50IGk9MDtpPG47IGkrKyl7CgkJCWlmIChkaXN0W2ldPG1uICYmICF1c2VkW2ldKXsKCQkJCW1uPWRpc3RbaV07CgkJCQl2PWk7CgkJCX0KCQl9CgkJCgl9Cn0KaW50IG1haW4oKSB7CglpbnQgcy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