#include <bits/stdc++.h>
using namespace std;
int n, m;
void dfs(vector<vector<char> > &grid, int x, int y) {
  if (x >= n || x < 0 || y < 0 || y >= m || grid[x][y] != '#') return;
  grid[x][y] = '*';
  dfs(grid, x + 1, y);
  dfs(grid, x - 1, y);
  dfs(grid, x, y + 1);
  dfs(grid, x, y - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  vector<vector<char> > grid(n, vector<char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  vector<int> rows(n);
  vector<int> cols(m);
  bool possible = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '#') {
        if (i > 0 && cols[j] > 0 && grid[i - 1][j] == '.') {
          possible = false;
        }
        if (j > 0 && rows[i] > 0 && grid[i][j - 1] == '.') {
          possible = false;
        }
        ++rows[i];
        ++cols[j];
      }
    }
  }
  if (!possible) {
    cout << -1 << endl;
    return 0;
  }
  int brows = count_if(rows.begin(), rows.end(), [](int i) { return i == 0; });
  int bcols = count_if(cols.begin(), cols.end(), [](int i) { return i == 0; });
  if ((brows > 0 && bcols == 0) || (bcols > 0 && brows == 0)) {
    possible = false;
    cout << -1 << endl;
    return 0;
  }
  int counter = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '#') {
        dfs(grid, i, j);
        counter++;
      }
    }
  }
  cout << counter << endl;
  return 0;
}
