#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1005][1005];
int col[1005], row[1005];
int main() {
  cin >> n >> m;
  bool emp = true;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < m; j++) {
      if (s[j] == '#') {
        a[i][j] = 1;
        emp = false;
      }
    }
  }
  if (emp) {
    cout << "0\n";
  } else {
    bool can = false;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        row[i] += a[i][j];
        col[j] += a[i][j];
      }
    }
    for (int i = 0; i < n; i++) {
      if (row[i] == 0) {
        can = true;
        for (int j = 0; j < m; j++) {
          if (col[j] == 0) can = false;
        }
        if (can) break;
      }
    }
    for (int j = 0; j < m; j++) {
      if (col[j] == 0) {
        can = true;
        for (int i = 0; i < n; i++) {
          if (row[i] == 0) can = false;
        }
        if (can) break;
      }
    }
    if (can) {
      cout << "-1\n";
      return 0;
    }
    for (int i = 0; i < n; i++) {
      bool was = false;
      for (int j = 0; j < m; j++) {
        if (a[i][j] == 0 && row[i] && was) can = true;
        if (a[i][j] == 1) {
          was = true;
          row[i]--;
        }
      }
    }
    for (int j = 0; j < m; j++) {
      bool was = false;
      for (int i = 0; i < n; i++) {
        if (a[i][j] == 0 && col[j] && was) can = true;
        if (a[i][j] == 1) {
          was = true;
          col[j]--;
        }
      }
    }
    if (can) {
      cout << "-1\n";
      return 0;
    }
    queue<pair<int, int>> q = queue<pair<int, int>>();
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i][j] == 1) {
          cnt++;
          q.push({i, j});
          while (!q.empty()) {
            int x = q.front().first, y = q.front().second;
            q.pop();
            if (a[x][y] == 2) continue;
            a[x][y] = 2;
            if (x > 0) {
              if (a[x - 1][y] == 1) {
                q.push({x - 1, y});
              }
            }
            if (y > 0) {
              if (a[x][y - 1] == 1) {
                q.push({x, y - 1});
              }
            }
            if (x < n - 1) {
              if (a[x + 1][y] == 1) {
                q.push({x + 1, y});
              }
            }
            if (y < m - 1) {
              if (a[x][y + 1] == 1) {
                q.push({x, y + 1});
              }
            }
          }
        }
      }
    }
    cout << cnt << "\n";
  }
}
