#include <bits/stdc++.h>
using namespace std;
vector<long long> par, rnk;
long long find_set(long long a) {
  if (a == par[a]) return a;
  return par[a] = find_set(par[a]);
}
void unite(long long a, long long b) {
  long long x = find_set(a);
  long long y = find_set(b);
  if (x != y) {
    if (rnk[x] < rnk[y]) swap(x, y);
    par[y] = x;
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n, m;
  cin >> n >> m;
  par.resize(m + 1);
  iota(par.begin(), par.end(), 0ll);
  rnk.resize(m + 1, 1);
  vector<string> arr(n);
  for (long long i = 0; i < n; i++) cin >> arr[i];
  long long p = 1;
  for (long long i = 0; i < n; i++) {
    long long d = 0;
    for (long long j = 0; j < m; j++) {
      if (arr[i][j] == '#' && d == 0)
        d = 1;
      else if (arr[i][j] == '#' && arr[i][j - 1] == '.' && d == 1) {
        p = 0;
        break;
      }
    }
    if (p == 0) break;
  }
  if (p == 0) {
    cout << -1 << "\n";
    return 0;
  }
  for (long long j = 0; j < m; j++) {
    long long d = 0;
    for (long long i = 0; i < n; i++) {
      if (arr[i][j] == '#' && d == 0)
        d = 1;
      else if (arr[i][j] == '#' && arr[i - 1][j] == '.' && d == 1) {
        p = 0;
        break;
      }
    }
    if (p == 0) break;
  }
  if (p == 0) {
    cout << -1 << "\n";
    return 0;
  }
  set<long long> second;
  for (long long i = 0; i < m; i++) second.insert(i);
  long long pr = 0, pc = 0;
  for (long long i = 0; i < n; i++) {
    long long d = 0;
    for (long long j = 0; j < m; j++)
      if (arr[i][j] == '#') d = 1;
    if (d == 0) pr = 1;
  }
  for (long long j = 0; j < m; j++) {
    long long d = 0;
    for (long long i = 0; i < n; i++)
      if (arr[i][j] == '#') d = 1;
    if (d == 0) pc = 1;
  }
  if (pr != pc) {
    cout << -1 << "\n";
    return 0;
  }
  vector<long long> done(m + 1, 0);
  for (long long i = 0; i < n; i++) {
    if (arr[i][m - 1] == '#') done[m - 1] = 1;
    for (long long j = 0; j < m - 1; j++) {
      if (arr[i][j] == '#' && arr[i][j + 1] == '#') unite(j, j + 1);
      if (arr[i][j] == '#') done[j] = 1;
    }
  }
  long long c = 0;
  for (long long i = 0; i < m + 1; i++)
    if (par[i] == i && done[i]) c++;
  cout << c << "\n";
}
