#include <bits/stdc++.h>
using namespace std;
string grid[1010];
bool row_has_black[1010];
bool col_has_black[1010];
int n, m;
void dfs(int i, int j) {
  grid[i][j] = 'x';
  if (i > 0 && grid[i - 1][j] == '#') dfs(i - 1, j);
  if (i < n - 1 && grid[i + 1][j] == '#') dfs(i + 1, j);
  if (j > 0 && grid[i][j - 1] == '#') dfs(i, j - 1);
  if (j < m - 1 && grid[i][j + 1] == '#') dfs(i, j + 1);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> grid[i];
  for (int i = 0; i < n; ++i) row_has_black[i] = false;
  for (int i = 0; i < m; ++i) col_has_black[i] = false;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (grid[i][j] == '#') {
        if (i > 1 && grid[i - 1][j] == '.' && col_has_black[j]) {
          cout << -1 << endl;
          return 0;
        }
        if (j > 1 && grid[i][j - 1] == '.' && row_has_black[i]) {
          cout << -1 << endl;
          return 0;
        }
        col_has_black[j] = true;
        row_has_black[i] = true;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    if (!row_has_black[i]) {
      bool ok = false;
      for (int j = 0; j < m; ++j) {
        if (!col_has_black[j]) {
          ok = true;
          break;
        }
      }
      if (!ok) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int j = 0; j < m; ++j) {
    if (!col_has_black[j]) {
      bool ok = false;
      for (int i = 0; i < n; ++i) {
        if (!row_has_black[i]) {
          ok = true;
          break;
        }
      }
      if (!ok) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (grid[i][j] == '#') {
        ++ans;
        dfs(i, j);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
