#include <bits/stdc++.h>
using namespace std;
void dfs(vector<string> &g, int i, int j) {
  g[i][j] = '.';
  vector<pair<int, int> > p = {
      {0, 1},
      {0, -1},
      {1, 0},
      {-1, 0},
  };
  for (auto c : p)
    if (i + c.first >= 0 && i + c.first < (int)g.size() && j + c.second >= 0 &&
        j + c.second < (int)g[0].size() && g[i + c.first][j + c.second] == '#')
      dfs(g, i + c.first, j + c.second);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> g(n);
  for (int i = 0; i < n; i++) cin >> g[i];
  bool em_row = false, em_col = false;
  set<int> rows, columns;
  for (int i = 0; i < n; i++) {
    int sections = 0, now = 0;
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '#' && now == 0) {
        sections++;
        now = 1;
      } else if (g[i][j] == '.')
        now = 0;
    }
    if (sections == 0) {
      em_row = true;
      rows.insert(i);
    } else if (sections > 1)
      return cout << -1 << endl, 0;
  }
  for (int j = 0; j < m; j++) {
    int sections = 0, now = 0;
    for (int i = 0; i < n; i++) {
      if (g[i][j] == '#' && now == 0) {
        sections++;
        now = 1;
      } else if (g[i][j] == '.')
        now = 0;
    }
    if (sections == 0) {
      em_col = true;
      columns.insert(j);
    } else if (sections > 1)
      return cout << -1 << endl, 0;
  }
  if (em_col != em_row) return cout << -1 << endl, 0;
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (g[i][j] == '#') {
        dfs(g, i, j);
        ans++;
      }
  cout << ans << endl;
  return 0;
}
