#include <bits/stdc++.h>
using namespace std;
pair<int, int> par[1010][1010];
int sz[1010][1010];
void init(int n, int m) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      par[i][j] = {i, j};
      sz[i][j] = 1;
    }
  }
}
pair<int, int> find(int x, int y) {
  if (par[x][y] == make_pair(x, y)) return {x, y};
  return par[x][y] = find(par[x][y].first, par[x][y].second);
}
void unite(int x1, int y1, int x2, int y2) {
  pair<int, int> p1 = find(x1, y1), p2 = find(x2, y2);
  if (p1 == p2) return;
  if (sz[p1.first][p1.second] > sz[p2.first][p2.second]) swap(p1, p2);
  par[p1.first][p1.second] = {p2.first, p2.second};
  sz[p2.first][p2.second] += sz[p1.first][p1.second];
}
string s[1010];
bool row[1010], col[1010];
int main() {
  int i, j, n, m;
  cin >> n >> m;
  init(n, m);
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '#' && i + 1 < n && s[i + 1][j] == '#')
        unite(i, j, i + 1, j);
      if (s[i][j] == '#' && j + 1 < m && s[i][j + 1] == '#')
        unite(i, j, i, j + 1);
    }
  }
  int ans = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '#' && find(i, j) == make_pair(i, j)) ans++;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (s[i][j] == '#') {
        row[i] = true;
        break;
      }
      if (j == m - 1) row[i] = false;
    }
  }
  for (j = 0; j < m; j++) {
    for (i = 0; i < n; i++) {
      if (s[i][j] == '#') {
        col[j] = true;
        break;
      }
      if (i == n - 1) col[j] = false;
    }
  }
  for (i = 0; i < n; i++) {
    if (row[i]) continue;
    for (j = 0; j < m; j++) {
      if (!col[j]) break;
      if (j == m - 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (j = 0; j < m; j++) {
    if (col[j]) continue;
    for (i = 0; i < n; i++) {
      if (!row[i]) break;
      if (i == n - 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (i = 0; i < n; i++) {
    if (!row[i]) continue;
    int l = 1010, r = -1;
    for (j = 0; j < m; j++) {
      if (s[i][j] == '#') {
        l = min(l, j);
        r = max(r, j);
      }
    }
    for (j = l; j <= r; j++) {
      if (s[i][j] == '.') {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (j = 0; j < m; j++) {
    if (!col[j]) continue;
    int l = 1010, r = -1;
    for (i = 0; i < n; i++) {
      if (s[i][j] == '#') {
        l = min(l, i);
        r = max(r, i);
      }
    }
    for (i = l; i <= r; i++) {
      if (s[i][j] == '.') {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}
