#include <bits/stdc++.h>
using namespace std;
int n, m;
bool isvalid(int x, int y) { return x < n && x >= 0 && y < m && y >= 0; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  vector<int> fr(n, 5000), lr(n, -1), fc(m, 5000), lc(m, -1);
  vector<string> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] == '#') {
        fr[i] = min(fr[i], j);
        fc[j] = min(fc[j], i);
        lr[i] = max(lr[i], j);
        lc[j] = max(lc[j], i);
      }
  int f = 1;
  int C, R;
  C = R = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      if (s[i][j] == '#') C = R = 1;
  }
  for (int i = 0; i < n; i++) {
    if (lr[i] == -1) continue;
    for (int j = fr[i]; j < lr[i]; j++)
      if (s[i][j] == '.') {
        f = 0;
        break;
      }
  }
  if (f)
    for (int j = 0; j < m; j++) {
      if (lc[j] == -1) continue;
      for (int i = fc[j]; i < lc[j]; i++)
        if (s[i][j] == '.') {
          f = 0;
          break;
        }
    }
  if (f && C) {
    for (int i = 0; i < n; i++) R &= (lr[i] != -1);
    for (int i = 0; i < m; i++) C &= (lc[i] != -1);
  }
  if (R == 0 && C == 1) f = 0;
  if (R == 1 && C == 0) f = 0;
  if (!f) {
    cout << -1 << '\n';
    return 0;
  }
  int a[n][m];
  memset(a, -1, sizeof a);
  int ans = 0;
  queue<pair<int, int> > Q;
  int x, y;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '#' && a[i][j] == -1) {
        ans++;
        Q.push(make_pair(i, j));
        while (!Q.empty()) {
          auto X = Q.front();
          Q.pop();
          tie(x, y) = X;
          if (a[x][y] != -1) continue;
          a[x][y] = ans;
          if (isvalid(x + 1, y))
            if (a[x + 1][y] == -1 && s[x + 1][y] == '#')
              Q.push(make_pair(x + 1, y));
          if (isvalid(x - 1, y))
            if (a[x - 1][y] == -1 && s[x - 1][y] == '#')
              Q.push(make_pair(x - 1, y));
          if (isvalid(x, y + 1))
            if (a[x][y + 1] == -1 && s[x][y + 1] == '#')
              Q.push(make_pair(x, y + 1));
          if (isvalid(x, y - 1))
            if (a[x][y - 1] == -1 && s[x][y - 1] == '#')
              Q.push(make_pair(x, y - 1));
        }
      }
    }
  int k = 0;
  cout << ans << '\n';
}
