program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
var A:array[1..100,1..100] of byte;
i,j,n,s,f,head,tail:integer;
B:array[1..100] of boolean;
cher,dist:array[1..100] of integer;
flag:boolean;
begin
read(n,s,f);
for i:=1 to n do
for j:=1 to n do
read(A[i,j]);
head:=1;
tail:=2;
cher[head]:=s;
B[s]:=true;
flag:=false;
dist[head]:=0;
while (head<tail) and (flag=false) do
begin
for j:=1 to n do
begin
if (a[cher[head],j]=1) and (B[j]=false) then
begin
cher[tail]:=j;
B[j]:=true;
dist[tail]:=dist[head]+1;
if j=f then
begin
flag:=true;
break;
end;
tail:=tail+1;
end;
end;
head:=head+1;
end;
if flag=false then write(0) else write(dist[tail]);
readln;
readln;
end.