#include <bits/stdc++.h>
using namespace std;
string s[1005];
long long dr[] = {0, 0, -1, 1};
long long dc[] = {1, -1, 0, 0};
long long n, m;
void dfs(long long i, long long j) {
  s[i][j] = '.';
  for (long long x = 0; x < 4; x++) {
    if (i + dr[x] >= 0 && i + dr[x] < n && j + dc[x] >= 0 && j + dc[x] < m &&
        s[i + dr[x]][j + dc[x]] == '#') {
      dfs(i + dr[x], j + dc[x]);
    }
  }
}
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> s[i];
  long long flag = 1, wr = 0, wc = 0;
  for (long long i = 0; i < n && flag; i++) {
    long long j = 0, k = m - 1;
    while (s[i][j] == '.' && j < k) j++;
    while (s[i][k] == '.' && j < k) k--;
    if (j == k && s[i][j] == '.') wr = 1;
    for (; j < k; j++)
      if (s[i][j] == '.') {
        flag = 0;
        break;
      }
  }
  for (long long i = 0; i < m && flag; i++) {
    long long j = 0, k = n - 1;
    while (s[j][i] == '.' && j < k) j++;
    while (s[k][i] == '.' && j < k) k--;
    if (j == k && s[j][i] == '.') wc = 1;
    for (; j < k; j++)
      if (s[j][i] == '.') {
        flag = 0;
        break;
      }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (s[i][j] == '#') {
        dfs(i, j);
        ans++;
      }
    }
  }
  if (ans == 0) {
    cout << "0\n";
    return 0;
  }
  if ((wr ^ wc) == 1 || flag == 0) {
    cout << "-1\n";
    return 0;
  }
  cout << ans << "\n";
}
