func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1100;   char str[N];   int G[N][N];   int sum_r[N], sum_c[N];   int n, m;   bool vis[N][N];   bool no() {     int r0 = n, c0 = m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         sum_r[i] += G[i][j];       }       if (sum_r[i]) r0--;     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) {         sum_c[j] += G[i][j];       }       if (sum_c[j]) c0--;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (G[i][j]) {           int k = j;           while (k <= m && G[i][k]) k++;           if (k - j != sum_r[i]) return true;           break;         }       }     }     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) {         if (G[i][j]) {           int k = i;           while (k <= n && G[k][j]) k++;           if (k - i != sum_c[j]) return true;           break;         }       }     }     for (int i = 1; i <= n; i++) {       if (sum_r[i] == 0) {         if (c0 == 0) return true;       }     }     for (int j = 1; j <= m; j++) {       if (sum_c[j] == 0) {         if (r0 == 0) return true;       }     }     return false;   }   vector<pair<int, int> > dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   void dfs(int x, int y) {     vis[x][y] = 1;     for (auto [dx, dy] : dir) {       int nx = x + dx, ny = y + dy;       if (vis[nx][ny]) continue;       if (G[nx][ny] && 0 < nx && nx <= n && 0 < ny && ny <= m) dfs(nx, ny);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , str + 1);       for (int j = 1; j <= m; j++) {         G[i][j] = str[j] ==  #  ? 1 : 0;       }     }     if (no()) {       puts( -1 );       return 0;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (G[i][j] && !vis[i][j]) {           dfs(i, j);           ans++;         }       }     }     printf( %d n , ans);     return 0;   }   