#include <bits/stdc++.h>
using namespace std;
int t, n, m;
char a[1100][1100];
void dfs(int x, int y) {
  a[x][y] = '.';
  if (x > 0 && a[x - 1][y] == '#') dfs(x - 1, y);
  if (y > 0 && a[x][y - 1] == '#') dfs(x, y - 1);
  if (x != n - 1 && a[x + 1][y] == '#') dfs(x + 1, y);
  if (y != m - 1 && a[x][y + 1] == '#') dfs(x, y + 1);
}
int main() {
  int ans = 0, f = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  int sum1 = 0, sum2 = 0;
  for (int i = 0; i < n; i++) {
    vector<int> v;
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') v.push_back(j);
    }
    for (int j = 1; j < v.size(); j++) {
      if (v[j] - v[j - 1] > 1) f = 1;
    }
    if (v.size()) sum1++;
  }
  for (int i = 0; i < m; i++) {
    vector<int> v;
    for (int j = 0; j < n; j++) {
      if (a[j][i] == '#') v.push_back(j);
    }
    for (int j = 1; j < v.size(); j++) {
      if (v[j] - v[j - 1] > 1) f = 1;
    }
    if (v.size()) sum2++;
  }
  if (f == 1 || (sum1 == n && sum2 != m) || (sum1 != n && sum2 == m)) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') {
        dfs(i, j);
        ans++;
      }
    }
  }
  cout << ans << endl;
}
