#include <bits/stdc++.h>
using namespace std;
char mat[1000][1000];
int n, m;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
void dfs(int y, int x) {
  if (y < 0 || x < 0 || y >= n || x >= m || mat[y][x] == '.') return;
  mat[y][x] = '.';
  for (int i = 0; i < 4; ++i) {
    dfs(y + dy[i], x + dx[i]);
  }
}
int main() {
  cin >> n >> m;
  for (int y = 0; y < n; ++y) {
    for (int x = 0; x < m; ++x) {
      cin >> mat[y][x];
    }
  }
  bool ok = true;
  int rowem = 0;
  for (int y = 0; y < n; ++y) {
    int ct = 0;
    for (int x = 0; x < m; ++x) {
      if (x > 0 && ct != 0 && mat[y][x] == '#' && mat[y][x - 1] == '.')
        ok = false;
      if (mat[y][x] == '#') ct++;
    }
    if (ct == 0) rowem++;
  }
  int colem = 0;
  for (int x = 0; x < m; ++x) {
    int ct = 0;
    for (int y = 0; y < n; ++y) {
      if (y > 0 && ct != 0 && mat[y][x] == '#' && mat[y - 1][x] == '.')
        ok = false;
      if (mat[y][x] == '#') ct++;
    }
    if (ct == 0) colem++;
  }
  if (colem != 0 && rowem == 0 || rowem != 0 && colem == 0) ok = false;
  int ans = 0;
  for (int y = 0; y < n; ++y) {
    for (int x = 0; x < m; ++x) {
      if (mat[y][x] == '#') {
        ++ans;
        dfs(y, x);
      }
    }
  }
  cout << (ok ? ans : -1) << '\n';
}
