#include <bits/stdc++.h>
using namespace std;
vector<int> ps;
int findp(int i) {
  if (ps[i] != i) ps[i] = findp(ps[i]);
  return ps[i];
}
void merge(int i, int j) {
  i = findp(i);
  j = findp(j);
  if (i != j) ps[j] = i;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  vector<int> mxr(n, -1);
  vector<int> mnr(n, m);
  vector<int> mxc(m, -1);
  vector<int> mnc(m, n);
  vector<vector<int> > t(n, vector<int>(m, 0));
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    for (int j = 0; j < (m); ++j) {
      if (a[i][j] == '#') {
        t[i][j] = 1;
        mxr[i] = j;
        if (mnr[i] == m) mnr[i] = j;
        mxc[j] = i;
        if (mnc[j] == n) mnc[j] = i;
      }
    }
  }
  int nbrv = 0;
  for (int i = 0; i < (n); ++i) {
    if (mxr[i] == -1) nbrv++;
  }
  int nbcv = 0;
  for (int j = 0; j < (m); ++j) {
    if (mxc[j] == -1) nbcv++;
  }
  bool isok = true;
  if (nbcv * nbrv == 0 and nbcv + nbrv != 0) isok = false;
  for (int i = 0; i < (n); ++i) {
    if (mxr[i] != -1) {
      for (int j = (mnr[i]); j < (mxr[i] + 1); ++j) {
        if (!t[i][j]) {
          isok = false;
          break;
        }
      }
    }
    if (!isok) break;
  }
  for (int j = 0; j < (m); ++j) {
    if (mxc[j] != -1) {
      for (int i = (mnc[j]); i < (mxc[j] + 1); ++i) {
        if (!t[i][j]) {
          isok = false;
          break;
        }
      }
    }
    if (!isok) break;
  }
  int nbg = 0;
  if (isok) {
    ps = vector<int>(n);
    for (int i = 0; i < (n); ++i) ps[i] = i;
    vector<int> whom(m, -1);
    for (int i = 0; i < (n); ++i) {
      if (mxr[i] != -1)
        for (int j = (mnr[i]); j < (mxr[i] + 1); ++j) {
          if (whom[j] != -1) {
            merge(whom[j], i);
          } else {
            whom[j] = i;
          }
        }
    }
    for (int i = 0; i < (n); ++i) {
      if (mxr[i] != -1 and ps[i] == i) nbg++;
    }
  }
  if (isok) {
    cout << nbg << "\n";
  } else {
    cout << "-1\n";
  }
}
