#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int M = 1e9 + 7;
const int MOD = 998244353;
const double PI = 3.141592653589793238460;
long long int power(long long int a, long long int b) {
  long long int res = 1;
  if (a == 0) return 0;
  if (a == 1) return 1;
  for (; b > 0; b >>= 1) {
    if (b & 1) res = (res * a);
    if (res > MOD) res %= MOD;
    a = (a * a);
    if (a > MOD) a = a % MOD;
  }
  return res;
}
bool isPrime[1000001];
vector<long long int> prime;
void seive(int limit) {
  isPrime[0] = isPrime[1] = 1;
  for (int i = 2; i * i <= limit; i++) {
    if (!isPrime[i])
      for (int j = i * i; j <= limit; j += i) {
        isPrime[j] = 1;
      }
  }
  for (int i = 2; i <= limit; i++)
    if (!isPrime[i]) prime.push_back(i);
}
int vis[1001][1001], n, m, ans = 0;
string s[1001];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
void dfs(int i, int j) {
  if (i < 0 || j < 0 || i >= n || j >= m) return;
  if (vis[i][j] || s[i][j] == '.') return;
  vis[i][j] = 1;
  for (int k = 0; k < 4; k++) {
    int x = i + dx[k];
    int y = j + dy[k];
    dfs(x, y);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> s[i];
  int sumr = 0, sumc = 0;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < m; j++) {
      int k = j;
      while (k < m and s[i][k] == '#') k++;
      if (s[i][j] == '#') sum++;
      j = k;
    }
    if (sum > 1) return cout << -1, 0;
    if (!sum) sumr++;
  }
  for (int i = 0; i < m; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      int k = j;
      while (k < n and s[k][i] == '#') k++;
      if (s[j][i] == '#') sum++;
      j = k;
    }
    if (sum > 1) return cout << -1, 0;
    if (!sum) sumc++;
  }
  if ((sumr and !sumc) || (sumc and !sumr)) return cout << -1, 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!vis[i][j] && s[i][j] == '#') {
        dfs(i, j);
        ans++;
      }
    }
  }
  cout << ans;
}
