#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[51][51];
int s[51][51];
int f[51][51][51][51];
int Sum(int x1, int y1, int x2, int y2) {
  return s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
}
void Input() {
  string st;
  scanf("%d\n", &n);
  for (int j = 1; j <= n; j++) {
    getline(cin, st);
    for (int i = 1; i <= n; i++)
      if (st[i - 1] == '#')
        a[i][j] = 1;
      else
        a[i][j] = 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
}
int Calc(int x1, int y1, int x2, int y2) {
  if (x1 > x2 || y1 > y2) return 0;
  if (x1 == x2 && y1 == y2) return a[x1][y1];
  if (Sum(x1, y1, x2, y2) == 0) return 0;
  if (f[x1][y1][x2][y2] != -1) return f[x1][y1][x2][y2];
  int res = max(y2 - y1 + 1, x2 - x1 + 1);
  for (int x = x1; x < x2; x++) {
    int t1 = Calc(x1, y1, x, y2);
    int t2 = Calc(x + 1, y1, x2, y2);
    res = min(res, t1 + t2);
  }
  for (int y = y1; y < y2; y++) {
    int t1 = Calc(x1, y1, x2, y);
    int t2 = Calc(x1, y + 1, x2, y2);
    res = min(res, t1 + t2);
  }
  f[x1][y1][x2][y2] = res;
  return res;
}
void Solve() {
  for (int x1 = 1; x1 <= n; x1++)
    for (int y1 = 1; y1 <= n; y1++)
      for (int x2 = x1; x2 <= n; x2++)
        for (int y2 = y1; y2 <= n; y2++) f[x1][y1][x2][y2] = -1;
  cout << Calc(1, 1, n, n);
}
int main() {
  Input();
  Solve();
}
