#include <bits/stdc++.h>
using namespace std;
vector<int> t;
void build(int v, int l, int r) {
  if (l + 1 == r) {
    t[v] = 1;
  } else {
    int m = (l + r) / 2;
    build(2 * v + 1, l, m);
    build(2 * v + 2, m, r);
    t[v] = t[2 * v + 1] + t[2 * v + 2];
  }
}
int sum(int v, int l, int r, int a, int b) {
  if (l >= b or r <= a) {
    return 0;
  } else if (a <= l and r <= b) {
    return t[v];
  } else {
    int m = (l + r) / 2;
    return sum(2 * v + 1, l, m, a, b) + sum(2 * v + 2, m, r, a, b);
  }
}
void update(int v, int l, int r, int pos, char value) {
  if (l == r - 1) {
    t[v] = value;
  } else {
    int m = (l + r) / 2;
    if (pos < m) {
      update(2 * v + 1, l, m, pos, value);
    } else {
      update(2 * v + 2, m, r, pos, value);
    }
    t[v] = t[2 * v + 1] + t[2 * v + 2];
  }
}
int f(int x1, int x2, int y1, int y2, vector<vector<vector<vector<int>>>>& dp,
      vector<vector<int>>& pref) {
  if (dp[x1][x2][y1][y2] != INT_MAX) {
    return dp[x1][x2][y1][y2];
  }
  int s =
      pref[x2 + 1][y2 + 1] - pref[x1][y2 + 1] - pref[x2 + 1][y1] + pref[x1][y1];
  if (s == 0) {
    return dp[x1][x2][y1][y2] = 0;
  } else {
    dp[x1][x2][y1][y2] = max(x2 - x1, y2 - y1) + 1;
    for (int i = x1; i < x2; i++) {
      dp[x1][x2][y1][y2] =
          min(dp[x1][x2][y1][y2],
              f(x1, i, y1, y2, dp, pref) + f(i + 1, x2, y1, y2, dp, pref));
    }
    for (int i = y1; i < y2; i++) {
      dp[x1][x2][y1][y2] =
          min(dp[x1][x2][y1][y2],
              f(x1, x2, y1, i, dp, pref) + f(x1, x2, i + 1, y2, dp, pref));
    }
    return dp[x1][x2][y1][y2];
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<vector<bool>> a(n, vector<bool>(n, false));
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < n; j++) {
      if (s[j] == '#') {
        a[i][j] = true;
      }
    }
  }
  vector<vector<int>> pref(n + 1, vector<int>(n + 1, 0));
  for (int i = 1; i <= n; i++) {
    pref[1][i] = pref[1][i - 1] + a[0][i - 1];
  }
  for (int i = 1; i <= n; i++) {
    pref[i][1] = pref[i - 1][1] + a[i - 1][0];
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 2; j <= n; j++) {
      pref[i][j] = a[i - 1][j - 1] + pref[i - 1][j] + pref[i][j - 1] -
                   pref[i - 1][j - 1];
    }
  }
  vector<vector<vector<vector<int>>>> dp(
      n, std::vector<vector<vector<int>>>(
             n, std::vector<vector<int>>(n, vector<int>(n, INT_MAX))));
  cout << f(0, n - 1, 0, n - 1, dp, pref);
  return 0;
}
