#include <bits/stdc++.h>
using namespace std;
bitset<100005> mark;
int main() {
  long long n, m, i, j, ii, x, y, k = 0, fail = 0, ans = 0;
  cin >> n >> m;
  string s;
  char a[n][m];
  long long b[n][m], row[n], column[m], rows = 0, columns = 0;
  for (i = 0; i < n; i++) {
    row[i] = 0;
  }
  for (i = 0; i < m; i++) {
    column[i] = 0;
  }
  for (i = 0; i < n; i++) {
    cin >> s;
    if (fail == 0) {
      for (j = 0; j < m; j++) {
        a[i][j] = s[j];
        if (a[i][j] == '#') {
          if (row[i] > 0 && a[i][j - 1] == '.') {
            fail = 1;
          }
          if (column[j] > 0 && a[i - 1][j] == '.') {
            fail = 1;
          }
          row[i]++;
          column[j]++;
          if (i > 0 && a[i - 1][j] == '#') {
            if (j > 0 && a[i][j - 1] == '#') {
              if (b[i][j - 1] != b[i - 1][j]) {
                b[i][j] = b[i - 1][j];
                mark[b[i][j - 1]] = false;
              } else {
                b[i][j] = b[i][j - 1];
              }
            } else {
              b[i][j] = b[i - 1][j];
            }
          } else if (j > 0 && a[i][j - 1] == '#') {
            b[i][j] = b[i][j - 1];
          } else {
            k++;
            b[i][j] = k;
            mark[k] = true;
          }
        } else {
          b[i][j] = 0;
        }
      }
    }
  }
  if (fail == 0) {
    for (i = 0; i < n; i++) {
      if (row[i] == 0) {
        rows++;
      }
    }
    for (i = 0; i < m; i++) {
      if (column[i] == 0) {
        columns++;
      }
    }
    if (rows > 0 && columns == 0) {
      fail = 1;
    } else if (columns > 0 && rows == 0) {
      fail = 1;
    }
  }
  if (fail == 1) {
    cout << "-1" << endl;
  } else {
    for (i = 0; i < k + 1; i++) {
      if (mark[i] == true) {
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
