#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> grid(n);
  for (int i = 0; i < n; i++) cin >> grid[i];
  bool zero = true;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (grid[i][j] == '#') zero = false;
  if (zero) {
    cout << 0;
    exit(0);
  }
  auto check_ans = [&]() -> bool {
    vector<pair<int, int>> okr(n, make_pair(m, -1));
    vector<pair<int, int>> okc(m, make_pair(n, -1));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (grid[i][j] == '#') {
          okr[i].first = min(okr[i].first, j);
          okr[i].second = max(okr[i].second, j);
          okc[j].first = min(okc[j].first, i);
          okc[j].second = max(okc[j].second, i);
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (okr[i].second == -1) {
        bool ok = false;
        for (int j = 0; j < m; j++) {
          if (okc[j].second == -1) ok = true;
        }
        if (!ok) return false;
      } else {
        for (int j = okr[i].first; j <= okr[i].second; j++) {
          if (grid[i][j] == '.') return false;
        }
      }
    }
    for (int i = 0; i < m; i++) {
      if (okc[i].second == -1) {
        bool ok = false;
        for (int j = 0; j < n; j++) {
          if (okr[j].second == -1) ok = true;
        }
        if (!ok) return false;
      } else {
        for (int j = okc[i].first; j <= okc[i].second; j++) {
          if (grid[j][i] == '.') return false;
        }
      }
    }
    return true;
  };
  if (!check_ans()) {
    cout << -1;
    exit(0);
  }
  vector<vector<bool>> vis(n, vector<bool>(m));
  auto bfs = [&](int x, int y) {
    const int dx[] = {1, -1, 0, 0};
    const int dy[] = {0, 0, 1, -1};
    queue<pair<int, int>> q;
    q.push(make_pair(x, y));
    vis[x][y] = true;
    while (!q.empty()) {
      int nowx = q.front().first, nowy = q.front().second;
      q.pop();
      for (int d = 0; d < 4; d++) {
        int gox = nowx + dx[d], goy = nowy + dy[d];
        if (gox < 0 || goy < 0 || gox >= n || goy >= m) continue;
        if (grid[gox][goy] == '.') continue;
        if (vis[gox][goy]) continue;
        vis[gox][goy] = true;
        q.push(make_pair(gox, goy));
      }
    }
  };
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '.' || vis[i][j]) continue;
      ans++;
      bfs(i, j);
    }
  }
  cout << ans;
  return 0;
}
