#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long res = 1;
  a = a % 1000000007;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % 1000000007;
      b--;
    }
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
long long fermat_inv(long long y) { return power(y, 1000000007 - 2); }
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
string s[1000];
vector<vector<bool>> visited(1000, vector<bool>(1000));
int n, m;
void dfs(int vr, int vc) {
  visited[vr][vc] = true;
  if (vr - 1 >= 0 && visited[vr - 1][vc] == false && s[vr - 1][vc] == '#') {
    dfs(vr - 1, vc);
  }
  if (vr + 1 < n && visited[vr + 1][vc] == false && s[vr + 1][vc] == '#') {
    dfs(vr + 1, vc);
  }
  if (vc - 1 >= 0 && visited[vr][vc - 1] == false && s[vr][vc - 1] == '#') {
    dfs(vr, vc - 1);
  }
  if (vc + 1 < m && visited[vr][vc + 1] == false && s[vr][vc + 1] == '#') {
    dfs(vr, vc + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> s[i];
    int check = 1;
    int cr = 0;
    int cc = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (s[i][j] == '#') {
          cr++;
          int k = j;
          while (k < m && s[i][k] == '#') k++;
          for (int l = k; l < m; l++) {
            if (s[i][l] == '#') check = 0;
          }
          break;
        }
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        if (s[j][i] == '#') {
          cc++;
          int k = j;
          while (k < n && s[k][i] == '#') k++;
          for (int l = k; l < n; l++) {
            if (s[l][i] == '#') check = 0;
          }
          break;
        }
      }
    }
    if (check == 0 || (cr != n && cc == m) || (cc != m && cr == n))
      cout << "-1\n";
    else {
      long long ans = 0;
      for (long long i = 0; i < n; i++) {
        for (long long j = 0; j < m; j++) {
          if (s[i][j] == '#' && visited[i][j] == false) {
            ans++;
            dfs(i, j);
          }
        }
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
