Загрузка данных


n, start, finish = map(int, input().split())
start -= 1
finish -= 1

matrix = []
for i in range(n):
    matrix.append(list(map(int, input().split())))

dist = [-1] * n
dist[start] = 0
visited = []

while len(visited) < n:
    curr = -1
    for i in range(n):
        if i not in visited and dist[i] != -1:
            if curr == -1 or dist[i] < dist[curr]:
                curr = i

    if curr == -1:
        break

    visited.append(curr)

    for next_node in range(n):
        weight = matrix[curr][next_node]
        if weight != -1:
            new_dist = dist[curr] + weight
            if dist[next_node] == -1 or new_dist < dist[next_node]:
                dist[next_node] = new_dist

print(dist[finish])