#include <bits/stdc++.h>
using ll = long long;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
using p = std::pair<int, int>;
int n, m;
std::vector<std::string> stage;
std::vector<std::vector<int>> color;
int num = 0;
void dfs(p u, p pre = p(-1, -1)) {
  color[u.first][u.second] = num;
  for (int i = 0; i < 4; i++) {
    int next_f = u.first + dy[i];
    int next_s = u.second + dx[i];
    if (next_f < 0 || next_f >= n) continue;
    if (next_s < 0 || next_s >= m) continue;
    p next = p(next_f, next_s);
    if (next == pre || color[next_f][next_s] != -1) continue;
    if (stage[next_f][next_s] == '#') {
      dfs(next, u);
    }
  }
}
int main() {
  std::cin >> n >> m;
  stage.resize(n);
  for (int i = 0; i < n; i++) {
    std::cin >> stage[i];
  }
  bool existAllWhiteRow = false, existAllWhiteCol = false;
  for (int i = 0; i < n; i++) {
    if (stage[i] == std::string(m, '.')) {
      existAllWhiteRow = true;
      break;
    }
  }
  for (int j = 0; j < m; j++) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (stage[i][j] == '.') cnt++;
    }
    if (cnt == n) existAllWhiteCol = true;
  }
  if (existAllWhiteCol != existAllWhiteRow) {
    std::cout << -1 << std::endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      if (cnt >= 0 && stage[i][j] == '#') {
        cnt++;
      } else if (cnt > 0 && stage[i][j] == '.') {
        cnt = -1;
      } else if (stage[i][j] == '#') {
        std::cout << -1 << std::endl;
        return 0;
      }
    }
  }
  for (int j = 0; j < m; j++) {
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (cnt >= 0 && stage[i][j] == '#') {
        cnt++;
      } else if (cnt > 0 && stage[i][j] == '.') {
        cnt = -1;
      } else if (stage[i][j] == '#') {
        std::cout << -1 << std::endl;
        return 0;
      }
    }
  }
  color.assign(n, std::vector<int>(m, -1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (stage[i][j] == '#' && color[i][j] == -1) {
        dfs(p(i, j));
        num++;
      }
    }
  }
  std::cout << num << std::endl;
  return 0;
}
