#include <bits/stdc++.h>
using namespace std;
char maze[1005][1005];
int vis[1005][1005];
int rowl[1005], rowr[1005], cloumnl[1005], cloumnr[1005];
int d[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
int n, m;
void dfs(int x, int y) {
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) {
    int newx = x + d[i][0];
    int newy = y + d[i][1];
    if (newx < 1 || newx > n || newy < 1 || newy > m || vis[newx][newy] ||
        maze[newx][newy] == '.')
      continue;
    dfs(newx, newy);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) rowl[i] = 1e9;
  for (int i = 1; i <= m; i++) cloumnl[i] = 1e9;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> maze[i][j];
      if (maze[i][j] == '#') {
        rowl[i] = min(rowl[i], j);
        rowr[i] = max(rowr[i], j);
        cloumnl[j] = min(cloumnl[j], i);
        cloumnr[j] = max(cloumnr[j], i);
      }
    }
  }
  int whiter = 0, whitec = 0;
  for (int i = 1; i <= n; i++) {
    int flag = 0;
    for (int j = 1; j <= m; j++) {
      if (maze[i][j] == '#') {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      whiter = 1;
      break;
    }
  }
  for (int i = 1; i <= m; i++) {
    int flag = 0;
    for (int j = 1; j <= n; j++) {
      if (maze[j][i] == '#') {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      whitec = 1;
      break;
    }
  }
  if (whiter + whitec == 1) {
    cout << -1 << '\n';
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = rowl[i] + 1; j < rowr[i]; j++) {
      if (maze[i][j] == '.') {
        cout << -1 << '\n';
        return 0;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = cloumnl[i] + 1; j < cloumnr[i]; j++) {
      if (maze[j][i] == '.') {
        cout << -1 << '\n';
        return 0;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (maze[i][j] == '#') {
        if (vis[i][j] == 0) {
          dfs(i, j);
          ans++;
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
