#include <bits/stdc++.h>
using namespace std;
const int oo = 1005;
const long long MOD = 1e9 + 7;
int n, m, res, f[oo][oo];
char x;
void dfs(int i, int j) {
  if (!f[i][j])
    return;
  else
    --f[i][j];
  dfs(i, j + 1);
  dfs(i, j - 1);
  dfs(i + 1, j);
  dfs(i - 1, j);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1, _b = n; i <= _b; i++)
    for (int j = 1, _b = m; j <= _b; j++) {
      cin >> x;
      f[i][j] = (x == '#');
    }
  int rw = 0;
  for (int i = 1, _b = n; i <= _b; i++) {
    int tmp = 0;
    for (int j = 1, _b = m; j <= _b; j++)
      if (f[i][j] && !f[i][j - 1]) ++tmp;
    if (tmp > 1) {
      cout << -1;
      return 0;
    }
    if (!tmp) rw = 1;
  }
  int cm = 0;
  for (int j = 1, _b = m; j <= _b; j++) {
    int tmp = 0;
    for (int i = 1, _b = n; i <= _b; i++)
      if (f[i][j] && !f[i - 1][j]) ++tmp;
    if (tmp > 1) {
      cout << -1;
      return 0;
    }
    if (!tmp) cm = 1;
  }
  if (rw + cm == 1) {
    cout << -1;
    return 0;
  }
  res = 0;
  for (int i = 1, _b = n; i <= _b; i++)
    for (int j = 1, _b = m; j <= _b; j++)
      if (f[i][j]) dfs(i, j), ++res;
  cout << res;
}
