#include <bits/stdc++.h>
using namespace std;
char a[1001][1001];
long long int countcomp(long long int n, long long int m) {
  set<pair<long long int, long long int> > s;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (a[i][j] == '#') s.insert(make_pair(i, j));
    }
  }
  long long int count = 0;
  while (!s.empty()) {
    count++;
    pair<long long int, long long int> node = *s.begin();
    queue<pair<long long int, long long int> > q;
    q.push(node);
    s.erase(node);
    while (!q.empty()) {
      pair<long long int, long long int> x = q.front();
      q.pop();
      long long int i = x.first;
      long long int j = x.second;
      if (s.find(make_pair(i + 1, j)) != s.end()) {
        q.push(make_pair(i + 1, j));
        s.erase(make_pair(i + 1, j));
      }
      if (s.find(make_pair(i - 1, j)) != s.end()) {
        q.push(make_pair(i - 1, j));
        s.erase(make_pair(i - 1, j));
      }
      if (s.find(make_pair(i, j + 1)) != s.end()) {
        q.push(make_pair(i, j + 1));
        s.erase(make_pair(i, j + 1));
      }
      if (s.find(make_pair(i, j - 1)) != s.end()) {
        q.push(make_pair(i, j - 1));
        s.erase(make_pair(i, j - 1));
      }
    }
  }
  return count;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, m;
  cin >> n >> m;
  long long int fl = 1;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == '#') fl = 0;
    }
  }
  if (fl) {
    cout << 0 << endl;
    return 0;
  }
  long long int allwhiterow = 0;
  long long int allwhitecol = 0;
  for (long long int i = 0; i < n; i++) {
    fl = 1;
    for (long long int j = 0; j < m; j++) {
      if (a[i][j] == '#') fl = 0;
    }
    if (fl) allwhiterow = 1;
  }
  for (long long int j = 0; j < m; j++) {
    fl = 1;
    for (long long int i = 0; i < n; i++) {
      if (a[i][j] == '#') fl = 0;
    }
    if (fl) allwhitecol = 1;
  }
  if (allwhiterow + allwhitecol == 1) {
    cout << -1 << endl;
    return 0;
  }
  fl = 0;
  for (long long int i = 0; i < n; i++) {
    long long int l = -1;
    long long int r = -1;
    for (long long int j = 0; j < m; j++) {
      if (a[i][j] == '#' && l == -1)
        l = j;
      else if (a[i][j] == '#')
        r = j;
    }
    for (long long int j = l + 1; j < r; j++) {
      if (a[i][j] == '.') {
        fl = 1;
        break;
      }
    }
    if (fl) break;
  }
  if (fl) {
    cout << -1 << endl;
    return 0;
  }
  fl = 0;
  for (long long int j = 0; j < m; j++) {
    long long int l = -1, r = -1;
    for (long long int i = 0; i < n; i++) {
      if (a[i][j] == '#' && l == -1)
        l = i;
      else if (a[i][j] == '#')
        r = i;
    }
    for (long long int i = l + 1; i < r; i++) {
      if (a[i][j] == '.') {
        fl = 1;
        break;
      }
    }
    if (fl) break;
  }
  if (fl) {
    cout << -1 << endl;
    return 0;
  }
  long long int ans = countcomp(n, m);
  cout << ans << endl;
}
