import java.util.*;
import java.lang.*;
import java.io.*;
class Graphdfs
{
private int[][] matrix; // Матрица смежности будет записана именно сюда.
private int n; // Число вершин.
private int[] was;// Массив цвета вершины.
public Graphdfs(){}
public Graphdfs(int n)
{
this.n = n;
matrix = new int [n][n];
was = new int [n];
}
public void setMatrix(Scanner in)
{
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
matrix[i][j] = in.nextInt();
}
public void showMatrix()
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
System.
out.
print(matrix
[i
][j
]); if(j
< n
- 1) System.
out.
print(" "); }
}
}
public boolean dfs(int key)
{
was[key] = 1;
for(int i = 0; i < n; i++)
{
if(matrix[key][i] != 0)
{
if(was[i] == 0){
if(dfs(i)) return true;
}
else if(was[i] == 1){
return true;
}
}
}
was[key] = 2;
return false;
}
public int[] getWas(){
return was;
}
}
public class Main
{
{
Scanner in
= new Scanner
(System.
in); int n = in.nextInt();
Graphdfs Graph = new Graphdfs(n);
Graph.setMatrix(in);
Graph.showMatrix();
for(int i = 0; i < n; i++){
if(Graph.
getWas()[i
] == 0 &&Graph.
dfs(i
) == true) {System.
out.
println(1); System.
exit(0);} }
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpjbGFzcyBHcmFwaGRmcwp7Cglwcml2YXRlIGludFtdW10gbWF0cml4OyAvLyDQnNCw0YLRgNC40YbQsCDRgdC80LXQttC90L7RgdGC0Lgg0LHRg9C00LXRgiDQt9Cw0L/QuNGB0LDQvdCwINC40LzQtdC90L3QviDRgdGO0LTQsC4KCXByaXZhdGUgaW50IG47IC8vINCn0LjRgdC70L4g0LLQtdGA0YjQuNC9LiAKCXByaXZhdGUgaW50W10gd2FzOy8vINCc0LDRgdGB0LjQsiDRhtCy0LXRgtCwINCy0LXRgNGI0LjQvdGLLgoJcHVibGljIEdyYXBoZGZzKCl7fQoJcHVibGljIEdyYXBoZGZzKG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