#include <bits/stdc++.h>
using namespace std;
vector<int> X = {0, 0, -1, 1};
vector<int> Y = {-1, 1, 0, 0};
bool isvalid(int x, int y, vector<vector<char> > &A) {
  int n = A.size();
  int m = A[0].size();
  if (x >= 0 && x < n && y >= 0 && y < m && A[x][y] == '#') return true;
  return false;
}
void dfs(int x, int y, vector<vector<char> > &A, vector<vector<bool> > &vis) {
  vis[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int xi = x + X[i];
    int yi = y + Y[i];
    if (isvalid(xi, yi, A) && vis[xi][yi] == false) {
      dfs(xi, yi, A, vis);
    }
  }
  return;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char> > A(n, vector<char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  if (n == 1) {
    for (int j = 0; j < m; j++) {
      if (A[0][j] == '#') {
        break;
      }
      if (j == m - 1) {
        cout << 0;
        return 0;
      }
    }
    for (int j = 0; j < m; j++) {
      if (A[0][j] == '.') {
        cout << -1;
        return 0;
      }
    }
  }
  if (m == 1) {
    for (int i = 0; i < n; i++) {
      if (A[i][0] == '#') {
        break;
      }
      if (i == n - 1) {
        cout << 0;
        return 0;
      }
    }
    for (int i = 0; i < n; i++) {
      if (A[i][0] == '.') {
        cout << -1;
        return 0;
      }
    }
  }
  int flc = 0, flr = 0;
  for (int i = 0; i < n; i++) {
    int j = 0;
    while (j < m && A[i][j] == '.') {
      j++;
    }
    if (j == m) flc = 1;
    while (j < m && A[i][j] == '#') {
      j++;
    }
    while (j < m && A[i][j] == '.') {
      j++;
    }
    if (j < m) {
      cout << -1;
      return 0;
    }
  }
  for (int j = 0; j < m; j++) {
    int i = 0;
    while (i < n && A[i][j] == '.') {
      i++;
    }
    if (i == n) {
      flr = 1;
    }
    while (i < n && A[i][j] == '#') {
      i++;
    }
    while (i < n && A[i][j] == '.') {
      i++;
    }
    if (i < n) {
      cout << -1;
      return 0;
    }
  }
  if (flc + flr == 1) {
    cout << -1;
    return 0;
  }
  vector<vector<bool> > vis(n, vector<bool>(m, false));
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (A[i][j] == '#' && vis[i][j] == false) {
        dfs(i, j, A, vis);
        cnt++;
      }
    }
  }
  cout << cnt;
  return 0;
}
