import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

int n;
void main(){
	n = readln.chomp.to!int;
	bool[][] xss;
	foreach(j; 0 .. n){
		xss ~= readln.chomp.map!(x => (x == '#')).array;
		}
	
	bool[][][] q, nextq;
	q ~= xss;
	for(int d = 0; d < 6; d ++){
		foreach(m; q){
			if(m.isBlack){
				d.writeln;
				return;
				}
			else{
				foreach(j0; 0 .. n) foreach(i0; 0 .. n) nextq ~= move(m, i0, j0);
				}
			}
		q = nextq;
		nextq = [];
		}
	
	"-1".writeln;
	}

bool[][] move(bool[][] org, int i0, int j0){
	bool[][] res;
	foreach(j; 0 .. n){
		bool[] r;
		foreach(i; 0 .. n){
			if(j == j0) r ~= org[i][i0];
			else r ~= org[j][i];
			}
		res ~= r;
		}
	return res; 
	}

bool isBlack(bool[][] m){
	foreach(r; m) foreach(c; r) if(!c) return 0;
	
	return 1;
	}