#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long dot(complex<long long> c1, complex<long long> c2) {
  return imag(c1 * conj(c2));
}
double dot(complex<double> c1, complex<double> c2) {
  return imag(c1 * conj(c2));
}
long long point(complex<long long> c1, complex<long long> c2) {
  return real(c1 * conj(c2));
}
double point(complex<double> c1, complex<double> c2) {
  return real(c1 * conj(c2));
}
void solve() {
  int i, j, n, m;
  cin >> n >> m;
  string s[n];
  bool v[n + 2][m + 2];
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  memset(v, 0, sizeof v);
  for (i = 0; i < n + 2; i++) v[i][0] = v[i][m + 1] = 1;
  for (j = 0; j < m + 2; j++) v[0][j] = v[n + 1][j] = 1;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '.') v[i + 1][j + 1] = 1;
    }
  }
  int res = 0;
  queue<pair<int, int> > q;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (!v[i + 1][j + 1]) {
        q.push({i + 1, j + 1});
        res++;
      }
      v[i + 1][j + 1] = 1;
      while (!q.empty()) {
        pair<int, int> aux = q.front();
        q.pop();
        if (!v[aux.first + 1][aux.second]) q.push({aux.first + 1, aux.second});
        v[aux.first + 1][aux.second] = 1;
        if (!v[aux.first][aux.second + 1]) q.push({aux.first, aux.second + 1});
        v[aux.first][aux.second + 1] = 1;
        if (!v[aux.first - 1][aux.second]) q.push({aux.first - 1, aux.second});
        v[aux.first - 1][aux.second] = 1;
        if (!v[aux.first][aux.second - 1]) q.push({aux.first, aux.second - 1});
        v[aux.first][aux.second - 1] = 1;
      }
    }
  }
  bool bc, bf, b, c, d;
  bc = bf = 0;
  for (i = 0; i < n; i++) {
    b = c = 0;
    for (j = 0; j < m; j++) {
      if (s[i][j] == '#') {
        b = 1;
        if (c) res = -1;
      } else if (b)
        c = 1;
    }
    if (!b) bc = 1;
  }
  for (j = 0; j < m; j++) {
    b = c = 0;
    for (i = 0; i < n; i++) {
      if (s[i][j] == '#') {
        b = 1;
        if (c) res = -1;
      } else if (b)
        c = 1;
    }
    if (!b) bf = 1;
  }
  if ((!bc && bf) || (bc && !bf)) res = -1;
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t, cases;
  cases = 1;
  for (t = 0; t < cases; t++) {
    solve();
  }
}
