#include <bits/stdc++.h>
using namespace std;
int mod(int a, int b) { return a >= 0 ? a % b : (b + a % b) % b; }
int dceil(int a, int b) { return (a + b - 1) / b; }
int n, m;
char tab[1010][1010];
int di[4] = {0, 0, -1, 1};
int dj[4] = {-1, 1, 0, 0};
bool dfs(int i, int j) {
  if (i >= 0 && i < n && j >= 0 && j < m && tab[i][j] == '#') {
    tab[i][j] = '.';
    for (int k = 0; k < 4; k++) {
      int ni = i + di[k];
      int nj = j + dj[k];
      dfs(ni, nj);
    }
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int mi = 0; mi < n; mi++) {
    for (int mj = 0; mj < m; mj++) {
      cin >> tab[mi][mj];
    }
  }
  bool res = true;
  bool cols = false;
  bool rows = false;
  for (int i = 0; i < n; i++) {
    int stat = 0;
    for (int j = 0; j < m; j++) {
      if (tab[i][j] == '#') {
        if (stat == 0)
          stat = 1;
        else if (stat == 2)
          res = false;
      } else {
        if (stat == 1) stat = 2;
      }
    }
    if (stat == 0) rows = true;
  }
  for (int i = 0; i < m; i++) {
    int stat = 0;
    for (int j = 0; j < n; j++) {
      if (tab[j][i] == '#') {
        if (stat == 0)
          stat = 1;
        else if (stat == 2)
          res = false;
      } else {
        if (stat == 1) stat = 2;
      }
    }
    if (stat == 0) cols = true;
  }
  res = res && !(rows ^ cols);
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (dfs(i, j)) count++;
    }
  }
  if (res) {
    cout << count << "\n";
  } else {
    cout << -1 << "\n";
  }
  return 0;
}
