#include <bits/stdc++.h>
using namespace std;
char mm[1005][1005];
int dfs(int n, int m) {
  if (mm[n][m] == '.' || mm[n][m] == '\0' || m < 0 || n < 0) return 0;
  mm[n][m] = '.';
  dfs(n + 1, m);
  dfs(n, m + 1);
  dfs(n - 1, m);
  dfs(n, m - 1);
  return 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  int row[1005] = {0}, col[1005] = {0};
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) mm[i][j] = '.';
  for (int i = 0; i < n; i++) cin >> mm[i];
  int ans = 0;
  int flagx = 0, flagy = 0, flagz = 0;
  for (int i = 0; i < n; i++) {
    flagx = 0, flagy = 0, flagz = 0;
    for (int j = 0; j < m; j++) {
      if (mm[i][j] == '#') flagx = 1;
      if (flagx && mm[i][j] == '.') flagy = 1;
      if (flagx && flagy && mm[i][j] == '#') flagz = 1;
    }
    if (flagx && flagy && flagz) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int j = 0; j < m; j++) {
    flagx = 0, flagy = 0, flagz = 0;
    for (int i = 0; i < n; i++) {
      if (mm[i][j] == '#') flagx = 1;
      if (flagx && mm[i][j] == '.') flagy = 1;
      if (flagx && flagy && mm[i][j] == '#') flagz = 1;
    }
    if (flagx && flagy && flagz) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      row[i] += (mm[i][j] == '#');
      col[j] += (mm[i][j] == '#');
    }
  int ifc = 0, ifr = 0;
  for (int i = 0; i < n; i++)
    if (!row[i]) ifr = 1;
  for (int i = 0; i < m; i++)
    if (!col[i]) ifc = 1;
  if (ifr ^ ifc) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) ans += dfs(i, j);
  cout << ans << endl;
  return 0;
}
