#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> a;
vector<vector<int>> vis;
vector<int> mx = {1, -1, 0, 0}, my = {0, 0, +1, -1};
bool bad(int r, int c) {
  if (r < 0 || c < 0) return 1;
  if (r >= n || c >= m) return 1;
  if (vis[r][c]) return 1;
  if (a[r][c] == '.') return 1;
  return 0;
}
void dfs(int r, int c, int num) {
  if (bad(r, c)) return;
  vis[r][c] = num;
  for (int i = 0; i < 4; i++) {
    dfs(r + mx[i], c + my[i], num);
  }
}
int main() {
  cin >> n >> m;
  a.resize(n);
  vis.resize(n, vector<int>(m, 0));
  for (string& x : a) cin >> x;
  bool fll = 0;
  for (string& x : a) {
    for (char y : x) {
      if (y == '#') fll = 1;
    }
  }
  if (fll ^ 1) {
    cout << 0;
    return 0;
  }
  int num = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '.') continue;
      if (vis[i][j]) continue;
      dfs(i, j, ++num);
    }
  }
  int allwhiterow = 0, allwhitecolumn = 0;
  for (int i = 0; i < n; i++) {
    bool flg = 0;
    for (int j = 0; j < m; j++) {
      flg |= (a[i][j] == '#');
    }
    if (flg ^ 1) {
      allwhiterow++;
    }
  }
  for (int i = 0; i < m; i++) {
    bool flg = 0;
    for (int j = 0; j < n; j++) {
      flg |= (a[j][i] == '#');
    }
    if (flg ^ 1) {
      allwhitecolumn++;
    }
  }
  if (allwhitecolumn && allwhiterow == 0) {
    cout << -1;
    return 0;
  }
  if (allwhitecolumn == 0 && allwhiterow) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    int si = m, se = -1;
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') si = min(si, j), se = max(se, j);
    }
    for (; si <= se; si++) {
      if (a[i][si] == '.') {
        cout << -1;
        return 0;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    int si = n, se = -1;
    for (int j = 0; j < n; j++) {
      if (a[j][i] == '#') si = min(si, j), se = max(se, j);
    }
    for (; si <= se; si++) {
      if (a[si][i] == '.') {
        cout << -1;
        return 0;
      }
    }
  }
  cout << num;
  return 0;
}
