Matrix Reachability


You are given a directed graph with vertices numbered from 11 to nn. The graph is described by its adjacency matrix: the entry in row ii and column jj is 1 if there is a directed edge from vertex ii to vertex jj, and 0 otherwise.

Starting at vertex ss, determine every vertex that can be reached by following zero or more directed edges.

Input

The first line contains two integers nn and ss, the number of vertices and the starting vertex.

The next nn lines each contain nn integers. The jj-th integer on the ii-th of these lines is the adjacency matrix entry for the directed edge from vertex ii to vertex jj.

Output

Output one line containing all reachable vertices in increasing order, separated by spaces.

Constraints

  • 1≤n≤5001 \le n \le 500
  • 1≤s≤n1 \le s \le n
  • Each matrix entry is either 0 or 1.

Example 1

Input 1
4 1
0 1 1 0
0 0 0 1
0 0 0 0
0 0 1 0
Output 1
1 2 3 4
Explanation

From vertex 11, we can directly reach vertices 22 and 33. From vertex 22, we can reach vertex 44, so all vertices are reachable.

Example 2

Input 2
5 3
0 0 0 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 0 1
0 0 0 0 0
Output 2
3 4 5
Explanation

Starting at vertex 33, the only new vertices reachable are 44 and then 55.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.