A walk in a graph is a route that may pass through the same vertex and the same edge more than once. The length of a walk is the number of edges it contains.
Given a graph, write a program that finds the smallest nonnegative integer K such that the number of walks of length L is O(LK).
The number of walks being O(LK) means there is a constant C such that the number of walks of length L is at most C×LK for every positive integer L.
Input
The first line contains the number of vertices N(2≤N≤50).
Each of the next N lines gives the edges of the graph as an adjacency matrix. If the j-th character of the i-th line is Y, there is an edge from vertex i to vertex j; if it is N, there is no such edge. No edge joins a vertex to itself.
Output
Print the smallest nonnegative integer K that satisfies the condition. If no K satisfies it, print -1.
Hint
If three vertices are joined to each other in both directions, the number of walks of length L is 3×2L. That value cannot be written as O(LK) for any K.
In a graph with no cycle, the number of walks of length L is 0 once L reaches N.
If the graph consists only of cycles that share no vertex, the number of walks of length L equals N for every L.