#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <stack>
#include <stdio.h>
#include <map>
#include <set>
#include <time.h>
#include <string>
#include <fstream>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <assert.h>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define pdd pair<double,double>
#define pii pair<ll,ll>
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD2 1000000009
#define INF ((ll)1e+18)
#define x1 fldgjdflgjhrthrl
#define x2 fldgjdflgrtyrtyjl
#define y1 fldggfhfghjdflgjl
#define y2 ffgfldgjdflgjl
#define N 131072
#define SUM 377
#define MAG 33554431
#define RED 0
#define BLUE 1
#define maxlen 300500
typedef long long ll;
typedef long double ld;
using namespace std;
ll i,j,n,k,l,m,tot, flag,r,ans,z, K,x1,y1,x2,y2,x3,y3,x,y,h,num,h2,timer,sz,q,nn;
string s,t;
ll full[505], empt[505];
char c[505][505], d[505][505], b[505];
ll brute()
{
    ll i,j,k,l,max_ans = 6;
    for (i = 0; i < 27*27*27*27; i++)
    {
        x = i;
        vector<ll> f;
       for (j = 0; j < 12; j++)
        {
            f.push_back(x%3);
            x /= 3;
        }
        for (j = 0; j < 3; j++)
            for (k = 0; k < 3; k++)
                d[j][k] = c[j][k];
        for (j = 0; j < max_ans; j++)
        {
            ll x = f[j*2], y = f[j*2+1];
            for (k = 0; k < 3; k++)
                b[k] = d[x][k];
            for (k = 0; k < 3; k++)
                d[k][y] = b[k];
            ll flag = 1;
            for (k = 0; k < 3; k++)
                for (l = 0; l < 3; l++)
                    if (d[k][l] != '#')
                        flag = 0;
            if (flag)
                break;
        }
        max_ans = min(max_ans,j+1);

    }
    return max_ans;
}
int main() {
	//freopen("input.txt","r",stdin);
 	//freopen("output.txt","w",stdout);
    cin >> n;
    /*for (int jj = 6; jj < 512; jj++)
    {
        for (i = 0; i < n; i++)
            for (j = 0; j < n; j++)
                if ((jj&(1<<(i*n+j))) != 0)
                    c[i][j] = '#';
                else
                    c[i][j] = '.';*/
    for (i = 0; i < n; i++)
        scanf("%s",c[i]);
    ll flag = 0;
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            if (c[i][j] != '.')
                flag = 1;
    if (!flag)
    {
        cout << -1 << endl;
        return 0;
    }
    for (i = 0; i < n; i++)
        full[i] = empt[i] = 0;
    for (i = 0; i < n; i++)
    {
        ll flag = 1, flag1 = 1;
        for (j = 0; j < n; j++)
        {
            if (c[j][i] != '#')
                flag = 0;
            if (c[j][i] != '.')
                flag1 = 0;
        }
        if (flag)
            full[i] = 1;
        if (flag1)
            empt[i] = 1;
    }
    ll ans = 3*n;
    for (i = 0; i < n; i++)
    {
        ll tmp = 0;
            for (j = 0; j < n; j++)
            {
                if (j == i && empt[i] == 1)
                    tmp += 3;
                else
                if (c[i][j] == '.')
                    tmp += 2;
                else
                if (c[i][j] == '#' && !full[j])
                    tmp++;
            }
            ans = min(ans, tmp);
    }
    cout << ans << endl;
    /*    if (ans != brute())
        {
            cout << jj << endl;
            for (i = 0; i < n; i++)
                cout << c[i] << endl;
            cout << ans << " " << brute() << endl;
            return 0;
        }
    }*/
    return 0;
}


Measured memory_bytes: 512