#include <bits/stdc++.h>
using namespace std;
int n, m;
char mapa[1002][1002];
int visitados[1002][1002];
int rowSegs[1002], colSegs[1002];
bool whiteRows = false, whiteCols = false;
int nortes;
bool ok = true;
queue<pair<int, int> > q;
pair<int, int> deltas[4];
void busca() {
  pair<int, int> p;
  while (!q.empty()) {
    p = q.front();
    q.pop();
    for (int i = (0); i <= (3); i++) {
      if (mapa[p.first + deltas[i].first][p.second + deltas[i].second] == '#' &&
          visitados[p.first + deltas[i].first][p.second + deltas[i].second] ==
              0) {
        visitados[p.first + deltas[i].first][p.second + deltas[i].second] = 1;
        q.push({p.first + deltas[i].first, p.second + deltas[i].second});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  deltas[0] = {-1, 0};
  deltas[1] = {1, 0};
  deltas[2] = {0, -1};
  deltas[3] = {0, 1};
  cin >> n >> m;
  for (int i = (0); i <= (m + 1); i++) {
    mapa[i][0] = '.';
    mapa[i][n + 1] = '.';
  }
  for (int j = (1); j <= (n); j++) {
    mapa[0][j] = '.';
    mapa[m + 1][j] = '.';
    for (int i = (1); i <= (m); i++) {
      cin >> mapa[i][j];
      if (mapa[i][j] == '#' && mapa[i - 1][j] == '.') rowSegs[j]++;
      if (mapa[i][j] == '#' && mapa[i][j - 1] == '.') colSegs[i]++;
    }
  }
  for (int i = (1); i <= (n); i++) whiteRows |= rowSegs[i] == 0;
  for (int i = (1); i <= (m); i++) whiteCols |= colSegs[i] == 0;
  for (int i = (1); i <= (n); i++) {
    if (rowSegs[i] > 1 || (rowSegs[i] == 0 && !whiteCols)) {
      cout << "-1";
      return 0;
    }
  }
  for (int i = (1); i <= (m); i++) {
    if (colSegs[i] > 1 || (colSegs[i] == 0 && !whiteRows)) {
      cout << "-1";
      return 0;
    }
  }
  for (int j = (1); j <= (n); j++) {
    for (int i = (1); i <= (m); i++) {
      if (mapa[i][j] == '#' && visitados[i][j] == 0) {
        q.push({i, j});
        busca();
        nortes++;
        while (!q.empty()) q.pop();
      }
    }
  }
  cout << nortes;
  return 0;
}
