#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int64_t N;
char map[5000][5100];//h,w
int64_t countx[5000];
int64_t county[5000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	for (int64_t i = 0; i < N; ++i)
	{
		in >> map[i];
	}
	for (int64_t i = 0; i < N; ++i)for (int64_t j = 0; j < N; ++j)
	{
		if (map[i][j] == '#') { ++countx[i]; ++county[j]; }
	}
	if (std::all_of(countx, countx + N, [](auto& i) {return i == 0; })) {
		out << -1 << std::endl;
		return 0;
	}

	int64_t min_res = 2147483647;
	for (int32_t y = 0; y < N; ++y)
	{
		int64_t pass = N - countx[y];
		if (pass != 0) {
			bool ok = false;
			for (int32_t y2 = 0; y2 < N; ++y2)
			{
				if (map[y2][y] == '#') {
					ok = true;
					break;
				}
			}
			if (ok == false) {
				++pass;
			}
		}

		for (int32_t x = 0; x < N; ++x)
		{
			if (county[x] < N) {
				++pass;
			}
		}
		min_res = std::min(min_res, pass);
	}
	out << (min_res == 2147483647 ? -1 : min_res) << endl;

	return 0;
}
#endif

#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int64_t N;
char map[5000][5100];//h,w
int64_t countx[5000];
int64_t county[5000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	for (int64_t i = 0; i < N; ++i)
	{
		in >> map[i];
	}
	for (int64_t i = 0; i < N; ++i)for (int64_t j = 0; j < N; ++j)
	{
		if (map[i][j] == '#') { ++countx[i]; ++county[j]; }
	}

	int64_t min_res = 2147483647;
	for (int64_t i = 0; i < N; ++i)for (int64_t j = 0; j < N; ++j)
	{
		if (map[i][j] == '#') {
			int64_t tmp = 0;
			tmp += N - countx[j];
			for (int64_t x = 0; x < N; ++x)
			{
				if ((map[i][x] != '#') || county[x] < N) {
					++tmp;
				}
			}
			min_res = std::min(min_res, tmp);
		}
	}
	out << (min_res== 2147483647 ?-1: min_res) << endl;

	return 0;
}
#endif

#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int64_t N;
char map[500][510];



int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	for (int64_t i = 0; i < N; ++i)
	{
		in >> map[i];
	}

	int count = 0;
	for (int64_t i = 0; i < N; ++i)	for (int64_t j = 0; j < N; ++j)
	{
		if (map[i] == '#') { ++count; }
	}
	if (count == 0) {
		out << -1 << std::endl;
	}
	if (N*N == count) {
		out << 0 << std::endl;
	}
	if (N == 2) {
		if (count == 1) {
			out << 3 << std::endl;
		}
		if (count == 3) {
			out << 1 << std::endl;
		}
		if (count == 2) {
			if (map[0][0] == map[0][1]) {
				out << 2 << std::endl;
			}
			else {
				out << 3 << std::endl;
			}
		}
	}
	if (N == 3) {
		if (count == 1) {
			if (map[0][0] == '#' || map[2][2] == '#' || map[1][1] == '#') {
				out << 5 << std::endl;
			}
			if (map[0][1] == '#' || map[2][2] == '#' || map[1][1] == '#') {
				out << 6 << std::endl;
			}
		}
	}

	return 0;
}
#endif


Measured memory_bytes: 4096