#include <bits/stdc++.h>
using namespace std;
void test_case() {
  int N, M;
  cin >> N >> M;
  vector<string> a(N + 1);
  bool full_line = false;
  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
    int cnt = 0;
    a[i] = '0' + a[i];
    for (int j = 1; j <= M; ++j)
      if (a[i][j] == '#' && a[i][j] != a[i][j - 1]) ++cnt;
    if (cnt > 1) {
      cout << "-1\n";
      return;
    }
    if (cnt == 0) full_line = true;
  }
  bool full_col = false;
  for (int j = 1; j <= M && !full_col; ++j) {
    int cnt = 0;
    for (int i = 1; i <= N; ++i)
      if (a[i][j] == '#' && (i == 1 || a[i][j] != a[i - 1][j])) ++cnt;
    if (cnt > 1) {
      cout << "-1\n";
      return;
    }
    if (cnt == 0) full_col = true;
  }
  if (full_line != full_col) {
    cout << "-1\n";
    return;
  }
  int ans = 0;
  auto inside = [&](int lin, int col) -> bool {
    return lin > 0 && col > 0 && lin <= N && col <= M;
  };
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= M; ++j)
      if (a[i][j] == '#') {
        ++ans;
        queue<pair<int, int>> Q;
        Q.emplace(i, j);
        a[i][j] = '.';
        const int di[] = {-1, 0, 1, 0}, dj[] = {0, 1, 0, -1};
        while (!Q.empty()) {
          auto curr = Q.front();
          Q.pop();
          for (int k = 0; k < 4; ++k) {
            auto next = make_pair(curr.first + di[k], curr.second + dj[k]);
            if (inside(next.first, next.second) &&
                a[next.first][next.second] == '#') {
              Q.emplace(next);
              a[next.first][next.second] = '.';
            }
          }
        }
      }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  while (T--) test_case();
}
