#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
struct Pt {
  int i, j;
  Pt(int _i, int _j) : i(_i), j(_j) {}
};
int n, m;
bool check(Pt p) {
  int i = p.i, j = p.j;
  return i >= 0 && i < n && j >= 0 && j <= m;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  vector<string> vs(n);
  for (auto &s : vs) cin >> s;
  vector<pair<int, int>> dirs = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  int ccMax = 0;
  vector<vector<int>> cc(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (cc[i][j] || vs[i][j] == '.') continue;
      ccMax++;
      queue<Pt> q;
      q.push(Pt(i, j));
      cc[i][j] = ccMax;
      while (q.size()) {
        auto cur = q.front();
        q.pop();
        for (auto p : dirs) {
          Pt p2(cur.i + p.first, cur.j + p.second);
          if (check(p2) && vs[p2.i][p2.j] == '#' && !cc[p2.i][p2.j]) {
            cc[p2.i][p2.j] = ccMax;
            q.push(p2);
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int minj = m, maxj = -1;
    for (int j = 0; j < m; j++) {
      if (vs[i][j] == '#') {
        minj = min(minj, j);
        maxj = max(maxj, j);
      }
    }
    for (int j = minj; j <= maxj; j++) {
      if (vs[i][j] == '.') {
        cout << -1;
        return 0;
      }
    }
  }
  for (int j = 0; j < m; j++) {
    int mini = n, maxi = -1;
    for (int i = 0; i < n; i++) {
      if (vs[i][j] == '#') {
        mini = min(mini, i);
        maxi = max(maxi, i);
      }
    }
    for (int i = mini; i <= maxi; i++) {
      if (vs[i][j] == '.') {
        cout << -1;
        return 0;
      }
    }
  }
  vector<int> re, ce;
  for (int i = 0; i < n; i++) {
    if (vs[i].find('#') == -1) re.push_back(i);
  }
  for (int j = 0; j < m; j++) {
    int pos = -1;
    for (int i = 0; i < n; i++) {
      if (vs[i][j] == '#') {
        pos = i;
        break;
      }
    }
    if (pos == -1) ce.push_back(j);
  }
  for (int i : re) {
    for (int j : ce) {
      vs[i][j] = '#';
    }
  }
  for (int i = 0; i < n; i++) {
    if (vs[i].find('#') == -1) {
      cout << -1;
      return 0;
    }
  }
  for (int j = 0; j < m; j++) {
    int pos = -1;
    for (int i = 0; i < n; i++) {
      if (vs[i][j] == '#') {
        pos = i;
        break;
      }
    }
    if (pos == -1) {
      cout << -1;
      return 0;
    }
  }
  cout << ccMax;
  return 0;
}
