#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long maxn = (long long)2e6 + 5;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
long long T = 1;
long long dp[55][55][55][55];
char s[55][55];
long long dfs(long long x, long long y, long long x1, long long y1) {
  if (dp[x][y][x1][y1] != -1) return dp[x][y][x1][y1];
  if (x == x1 && y == y1) return dp[x][y][x1][y1] = (s[x][y] == '#');
  long long maxx = max(x1 - x + 1, y1 - y + 1);
  for (long long i = x; i <= x1 - 1; ++i)
    maxx = min(maxx, dfs(x, y, i, y1) + dfs(i + 1, y, x1, y1));
  for (long long i = y; i <= y1 - 1; ++i)
    maxx = min(maxx, dfs(x, y, x1, i) + dfs(x, i + 1, x1, y1));
  return dp[x][y][x1][y1] = maxx;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; ++i) cin >> (s[i] + 1);
  cout << dfs(1, 1, n, n);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  while (T--) solve();
  return 0;
}
