#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, 1, 0, -1};
bool iS[1005];
bool jS[1005];
long long iT;
long long jT;
long long n, m, ans = 0;
string mat[1005];
bool vis[1005][1005];
void solve(int i, int j) {
  if (vis[i][j]) return;
  ans++;
  queue<pair<int, int> > bfs;
  bfs.push({i, j});
  vis[i][j] = 1;
  while (bfs.size()) {
    pair<int, int> act = bfs.front();
    bfs.pop();
    int ci = act.first;
    int cj = act.second;
    for (int d = 0; d < 4; d++) {
      int ni = ci + di[d];
      int nj = cj + dj[d];
      if (ni < 0 or ni >= n or nj < 0 or nj >= m or vis[ni][nj] or
          mat[ni][nj] == '.')
        continue;
      vis[ni][nj] = 1;
      bfs.push({ni, nj});
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long tb = 0, tw = 0;
  cin >> n >> m;
  iT = n;
  jT = m;
  for (int i = 0; i < n; i++) {
    cin >> mat[i];
    for (char c : mat[i]) {
      if (c == '#')
        tb++;
      else
        tw++;
    }
  }
  vector<int> emp;
  for (int i = 0; i < n; i++) {
    bool bl = 0, wt = 0;
    for (int j = 0; j < m; j++) {
      if (mat[i][j] == '.' and bl) wt = 1;
      if (mat[i][j] == '#') {
        bl = 1;
        if (wt) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    if (bl) {
      iS[i] = 1;
      iT--;
    }
  }
  for (int j = 0; j < m; j++) {
    bool bl = 0, wt = 0;
    for (int i = 0; i < n; i++) {
      if (mat[i][j] == '.' and bl) wt = 1;
      if (mat[i][j] == '#') {
        bl = 1;
        if (wt) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    if (bl) {
      iS[j] = 1;
      jT--;
    }
  }
  if (min(iT, jT) == 0 and max(iT, jT) > 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mat[i][j] == '.') continue;
      solve(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}
