public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		do {
			line = in.readLine();
			if (line == null || line.length() == 0)
				break;
			size = Integer.parseInt(line);
			if (size == 0)
				break;
			m = new char[size][size];
			max = 0;
			for (int i = 0; i < size; i++)
				m[i] = in.readLine().toCharArray();
			rooked(0, 0, 0);
			out.append(max + "\n");
		} while (line != null && line.length() != 0);
		System.out.print(out);
	}