#include <bits/stdc++.h>
using namespace std;
int n, f[52][52][52][52];
string s[52];
int dfs(int lx, int rx, int ly, int ry) {
  if (f[lx][rx][ly][ry] != -1) return f[lx][rx][ly][ry];
  if (lx == rx && ly == ry)
    if (s[lx][ly] == '#')
      return 1;
    else
      return 0;
  int ans = max(rx - lx + 1, ry - ly + 1);
  for (int i = lx; i < rx; i++)
    ans = min(ans, dfs(lx, i, ly, ry) + dfs(i + 1, rx, ly, ry));
  for (int i = ly; i < ry; i++)
    ans = min(ans, dfs(lx, rx, ly, i) + dfs(lx, rx, i + 1, ry));
  return f[lx][rx][ly][ry] = ans;
}
int main() {
  memset(f, -1, sizeof(f));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  cout << dfs(1, n, 0, n - 1);
  return 0;
}
