#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long N = 1e3 + 1;
const long long md = 1e9 + 7;
vector<string> a(N);
long long R = 0, n, m;
bool us[N][N];
void dfs(long long i, long long j) {
  us[i][j] = true;
  if (i > 0 && us[i - 1][j] == 0 && a[i - 1][j] == '#') dfs(i - 1, j);
  if (i < n - 1 && us[i + 1][j] == 0 && a[i + 1][j] == '#') dfs(i + 1, j);
  if (j > 0 && us[i][j - 1] == 0 && a[i][j - 1] == '#') dfs(i, j - 1);
  if (j < m - 1 && us[i][j + 1] == 0 && a[i][j + 1] == '#') dfs(i, j + 1);
}
int main() {
  long long i, j, qq, w, r = 0, x, l, k, q, A = 0, B = 0;
  cin >> n >> m;
  for (long long i = 0; i < (n); i++) cin >> a[i];
  for (long long i = 0; i < (n); i++)
    for (long long j = 0; j < (m); j++) us[i][j] = false;
  for (long long i = 0; i < (n); i++)
    for (long long j = 0; j < (m); j++) {
      if (a[i][j] != '.' && us[i][j] == false) {
        R++;
        dfs(i, j);
      }
    }
  long long zz = 0;
  for (long long i = 0; i < (n); i++) {
    l = -1;
    r = -1;
    for (long long j = 0; j < (m); j++)
      if (a[i][j] == '#') {
        l = j;
        break;
      }
    for (int j = m - 1; j >= 0; j--)
      if (a[i][j] == '#') {
        r = j;
        break;
      }
    for (long long j = l; j < (r); j++)
      if (a[i][j] == '.') {
        zz = -1;
      }
    if (l == -1) A++;
  }
  for (long long j = 0; j < (m); j++) {
    l = -1;
    r = -1;
    for (long long i = 0; i < (n); i++)
      if (a[i][j] == '#') {
        l = i;
        break;
      }
    for (int i = n - 1; i >= 0; i--)
      if (a[i][j] == '#') {
        r = i;
        break;
      }
    for (long long i = l; i < (r); i++)
      if (a[i][j] == '.') {
        zz = -1;
      }
    if (l == -1) B++;
  }
  if (A == 0 && B != 0) zz = -1;
  if (A != 0 && B == 0) zz = -1;
  if (zz == 0)
    cout << R;
  else
    cout << -1;
}
