#include <bits/stdc++.h>
using namespace std;
char mp[1050][1050];
int n, m, dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
inline bool prim(int x, int y) { return x > 0 && y > 0 && x <= n && y <= m; }
void bfs(int x, int y) {
  mp[x][y] = '.';
  queue<pair<int, int> > q;
  q.push(pair<int, int>(x, y));
  while (!q.empty()) {
    pair<int, int> pd = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      int px = pd.first + dx[i], py = pd.second + dy[i];
      if (prim(px, py) && mp[px][py] == '#') {
        mp[px][py] = '.';
        q.push(pair<int, int>(px, py));
      }
    }
  }
}
void solve() {
  cin >> n >> m;
  bool emptyRow = false, emptyColumn = false;
  for (int i = 1; i <= n; i++) {
    cin >> (mp[i] + 1);
    int kd = 0;
    for (int j = 1; j <= m; j++) {
      if (mp[i][j] == '.') {
        if (kd == 1) kd = 2;
      } else {
        if (kd == 0)
          kd = 1;
        else if (kd == 2) {
          cout << "-1\n";
          return;
        }
      }
    }
    if (kd == 0) emptyColumn = true;
  }
  for (int j = 1; j <= m; j++) {
    int kd = 0;
    for (int i = 1; i <= n; i++) {
      if (mp[i][j] == '.') {
        if (kd == 1) kd = 2;
      } else {
        if (kd == 0)
          kd = 1;
        else if (kd == 2) {
          cout << "-1\n";
          return;
        }
      }
    }
    if (kd == 0) emptyRow = true;
  }
  if (emptyColumn != emptyRow) {
    cout << "-1\n";
    return;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (mp[i][j] == '#') {
        bfs(i, j);
        ans++;
      }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
