#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000000 + 7;
long long powe(long long x, long long y) {
  x = x % mod, y = y % (mod - 1);
  long long ans = 1;
  while (y > 0) {
    if (y & 1) {
      ans = (1ll * x * ans) % mod;
    }
    y >>= 1;
    x = (1ll * x * x) % mod;
  }
  return ans;
}
void fun() {}
const long long N = 1001;
long long x[4] = {0, 0, 1, -1};
long long y[4] = {1, -1, 0, 0};
long long ans;
long long vis[N][N];
string s[N];
long long n, m;
void dfs(long long i, long long j) {
  vis[i][j] = 1;
  for (long long k = 0; k < 4; k++) {
    long long nx = i + x[k];
    long long ny = j + y[k];
    if (nx >= 0 && nx < n && ny >= 0 && ny < m && !vis[nx][ny] &&
        s[nx][ny] == '#')
      dfs(nx, ny);
  }
}
signed main() {
  fun();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> s[i];
  long long flag1 = 0;
  long long flag2 = 0;
  for (long long i = 0; i < n; i++) {
    long long temp = 0;
    long long cnt = 0;
    for (long long j = 0; j < m; j++) {
      if (temp == 2 && s[i][j] == '#') {
        cout << -1;
        exit(0);
      }
      if (s[i][j] == '#') {
        temp = 1;
        cnt++;
      }
      if (temp == 1 && s[i][j] == '.') temp = 2;
    }
    if (cnt == 0) flag1 = 1;
  }
  for (long long i = 0; i < m; i++) {
    long long temp = 0;
    long long cnt = 0;
    for (long long j = 0; j < n; j++) {
      if (temp == 2 && s[j][i] == '#') {
        cout << -1;
        exit(0);
      }
      if (s[j][i] == '#') {
        temp = 1;
        cnt++;
      }
      if (temp == 1 && s[j][i] == '.') temp = 2;
    }
    if (cnt == 0) flag2 = 1;
  }
  if (flag1 ^ flag2) {
    cout << -1;
    exit(0);
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (s[i][j] == '#' && !vis[i][j]) {
        ans++;
        dfs(i, j);
      }
    }
  }
  cout << ans;
}
