#include <bits/stdc++.h>
using namespace std;
class XX {
 public:
  int i, j;
  XX(int x, int y) {
    i = x;
    j = y;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, ans = 0, c = 0, i, j;
  bool x = false, y = false;
  XX *w, *r;
  queue<XX *> q;
  cin >> n >> m;
  vector<vector<char> > a(n, vector<char>(m));
  vector<int> row(n, -10), col(m, -10);
  vector<vector<int> > vis(n, vector<int>(m, 0));
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') {
        if (row[i] != -10 && row[i] != j - 1) c = 1;
        row[i] = j;
        if (col[j] != -10 && col[j] != i - 1) c = 1;
        col[j] = i;
      }
    }
  }
  for (i = 0; i < n; i++) {
    if (row[i] == -10) {
      x = true;
      break;
    }
  }
  for (i = 0; i < m; i++) {
    if (col[i] == -10) {
      y = true;
      break;
    }
  }
  if (c == 1 || (x != y)) {
    cout << -1;
    return 0;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (a[i][j] == '#' && vis[i][j] == 0) {
        w = new XX(i, j);
        q.push(w);
        while (!q.empty()) {
          w = q.front();
          q.pop();
          if (w->j != 0 && vis[w->i][(w->j) - 1] == 0 &&
              a[w->i][(w->j) - 1] == '#') {
            r = new XX(w->i, (w->j) - 1);
            q.push(r);
            vis[w->i][(w->j) - 1] = 1;
          }
          if (w->i != 0 && vis[(w->i) - 1][(w->j)] == 0 &&
              a[(w->i) - 1][(w->j)] == '#') {
            r = new XX((w->i) - 1, (w->j));
            q.push(r);
            vis[(w->i) - 1][(w->j)] = 1;
          }
          if (w->i != n - 1 && vis[(w->i) + 1][(w->j)] == 0 &&
              a[(w->i) + 1][(w->j)] == '#') {
            r = new XX((w->i) + 1, (w->j));
            q.push(r);
            vis[(w->i) + 1][(w->j)] = 1;
          }
          if (w->j != m - 1 && vis[(w->i)][(w->j) + 1] == 0 &&
              a[(w->i)][(w->j) + 1] == '#') {
            r = new XX((w->i), (w->j) + 1);
            q.push(r);
            vis[(w->i)][(w->j) + 1] = 1;
          }
        }
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}
