#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O2")
#pragma GCC optimization("unroll-loops")
using namespace std;
short n, m;
string s[1001];
vector<short> b_hor[1001], b_ver[1001];
vector<pair<short, short> > g[1001][1001];
bool used[1001][1001];
void dfs(pair<int, int> u) {
  used[u.first][u.second] = 1;
  for (auto v : g[u.first][u.second]) {
    if (!used[v.first][v.second]) dfs(v);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == '#') {
        b_hor[i].push_back(j);
        b_ver[j].push_back(i);
        if (i && s[i - 1][j] == '#') {
          g[i][j].push_back(make_pair(i - 1, j));
          g[i - 1][j].push_back(make_pair(i, j));
        }
        if (j && s[i][j - 1] == '#') {
          g[i][j].push_back(make_pair(i, j - 1));
          g[i][j - 1].push_back(make_pair(i, j));
        }
      }
    }
  }
  bool fucked = 0, w_hor = 0, w_ver = 0;
  for (int i = 0; i < n; ++i) {
    if (b_hor[i].empty()) {
      w_hor = 1;
      continue;
    }
    for (int j = 0; j < int(b_hor[i].size()) - 1; ++j) {
      if (b_hor[i][j + 1] - b_hor[i][j] > 1) fucked = 1;
    }
  }
  for (int j = 0; j < m; ++j) {
    if (b_ver[j].empty()) {
      w_ver = 1;
      continue;
    }
    for (int i = 0; i < int(b_ver[j].size()) - 1; ++i) {
      if (b_ver[j][i + 1] - b_ver[j][i] > 1) fucked = 1;
    }
  }
  if (fucked || (w_hor ^ w_ver))
    cout << "-1\n";
  else {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (s[i][j] == '#' && !used[i][j]) {
          dfs(make_pair(i, j));
          ++ans;
        }
      }
    }
    cout << ans << '\n';
  }
}
