#include <bits/stdc++.h>
using namespace std;
char str[1100][1100];
long long n, m;
bool isValid() {
  for (int i = 0; i < n; i++) {
    bool bl = false;
    for (int j = 0; j < m; j++) {
      if (str[i][j] == '#' && !bl) {
        bl = true;
        continue;
      }
      if (str[i][j] == '#' && str[i][j - 1] == '.') return false;
    }
  }
  for (int j = 0; j < m; j++) {
    bool bl = false;
    for (int i = 0; i < n; i++) {
      if (str[i][j] == '#' && !bl) {
        bl = true;
        continue;
      }
      if (str[i][j] == '#' && str[i - 1][j] == '.') return false;
    }
  }
  bool r = false, c = false;
  for (int i = 0; i < n; i++) {
    long long counter = 0;
    for (int j = 0; j < m; j++) {
      counter += str[i][j] == '.';
    }
    if (counter == m) r = true;
  }
  for (int j = 0; j < m; j++) {
    long long counter = 0;
    for (int i = 0; i < n; i++) {
      counter += str[i][j] == '.';
    }
    if (counter == n) c = true;
  }
  return (c == r);
}
long long ans = 0;
bool visited[1100][1100];
void dfs(long long r, long long c) {
  if (r < 0 || r >= n || c < 0 || c >= m || visited[r][c] || str[r][c] == '.')
    return;
  visited[r][c] = true;
  dfs(r - 1, c);
  dfs(r + 1, c);
  dfs(r, c - 1);
  dfs(r, c + 1);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> str[i];
  if (!isValid()) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (str[i][j] == '#' && !visited[i][j]) {
        dfs(i, j);
        ans++;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
