#include <bits/stdc++.h>
using namespace std;
int n, m;
char A[1001][1001];
int dsu[1002001], cnt, tmp;
set<int> Q;
bool freq[1002001], awce = false, awre = false, iaw;
int find(int v) {
  if (dsu[v] == v) return v;
  return dsu[v] = find(dsu[v]);
}
void merge(int u, int v) {
  u = find(u);
  v = find(v);
  dsu[u] = v;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> A[i][j];
  for (int i = 0; i < n; i++) {
    iaw = true;
    for (int j = 0; j < m; j++)
      if (A[i][j] != '.') iaw = false;
    if (iaw) awre = true;
  }
  for (int j = 0; j < m; j++) {
    iaw = true;
    for (int i = 0; i < n; i++)
      if (A[i][j] != '.') iaw = false;
    if (iaw) awce = true;
  }
  if (awre ^ awce) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    iota(dsu, dsu + m, 0);
    for (int j = 0; j < m - 1; j++)
      if (A[i][j] == '#' && A[i][j + 1] == '#') merge(j, j + 1);
    Q.clear();
    for (int j = 0; j < m; j++)
      if (A[i][j] == '#') {
        Q.insert(find(j));
        if (Q.size() > 1) {
          cout << -1 << "\n";
          return 0;
        }
      }
  }
  for (int i = 0; i < m; i++) {
    iota(dsu, dsu + n, 0);
    for (int j = 0; j < n - 1; j++)
      if (A[j][i] == '#' && A[j + 1][i] == '#') merge(j, j + 1);
    Q.clear();
    for (int j = 0; j < n; j++)
      if (A[j][i] == '#') {
        Q.insert(find(j));
        if (Q.size() > 1) {
          cout << -1 << "\n";
          return 0;
        }
      }
  }
  iota(dsu, dsu + (n * m), 0);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (A[i][j] == '#') {
        if (i + 1 < n)
          if (A[i + 1][j] == '#') merge(i * m + j, (i + 1) * m + j);
        if (i - 1 >= 0)
          if (A[i - 1][j] == '#') merge(i * m + j, (i - 1) * m + j);
        if (j + 1 < m)
          if (A[i][j + 1] == '#') merge(i * m + j, i * m + j + 1);
        if (j - 1 >= 0)
          if (A[i][j - 1] == '#') merge(i * m + j, i * m + j - 1);
      }
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (A[i][j] == '#') {
        tmp = find(i * m + j);
        if (!freq[tmp]) {
          freq[tmp] = true;
          cnt++;
        }
      }
    }
  cout << cnt;
}
