#include <bits/stdc++.h>
using namespace std;
long long mod = 2000000000;
long long A[1005][1005];
long long cntA[1001], cntB[1001];
long long xa[4] = {0, 0, 1, -1};
long long ya[4] = {1, -1, 0, 0};
long long n, m;
long long vis[1005][1005];
long long check(long long x, long long y) {
  if (x >= 0 && y >= 0 && x < n && y < m)
    return 1;
  else
    return 0;
}
void dfs(long long x, long long y) {
  vis[x][y] = 1;
  for (long long i = 0; i < 4; i++) {
    long long xx = x + xa[i];
    long long yy = y + ya[i];
    if (check(xx, yy) == 1 && A[xx][yy] == 1 && vis[xx][yy] == 0) {
      dfs(xx, yy);
    }
  }
}
signed main() {
  cin >> n >> m;
  long long ch = 1;
  set<long long> X, Y;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      char a;
      cin >> a;
      if (a == '#') {
        A[i][j] = 1;
        X.insert(i);
        Y.insert(j);
        if (i > 0) {
          if (A[i - 1][j] == 0) cntB[j]++;
        } else
          cntB[j]++;
        if (j > 0) {
          if (A[i][j - 1] == 0) cntA[i]++;
        } else
          cntA[i]++;
        if (cntA[i] > 1) ch = 0;
        if (cntB[j] > 1) ch = 0;
      }
    }
  }
  long long nn = n - X.size();
  long long mm = m - Y.size();
  if ((nn == 0 && mm > 0) || (nn > 0 && mm == 0)) ch = 0;
  long long cnt = 0;
  if (ch == 0)
    cout << -1 << endl;
  else {
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (vis[i][j] == 0 && A[i][j] == 1) {
          dfs(i, j);
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
}
