#include <bits/stdc++.h>
using namespace std;
char a[1010][1010];
bool x[1010], y[1010];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void dfs(int xx, int yy) {
  a[xx][yy] = '.';
  for (int i = 0; i < 4; i++) {
    int xxx = xx + dx[i];
    int yyy = yy + dy[i];
    if (a[xxx][yyy] == '#') dfs(xxx, yyy);
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  int flag = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') {
        if (x[i] && j && a[i][j - 1] != '#') {
          flag = 0;
          break;
        }
        if (y[j] && i && a[i - 1][j] != '#') {
          flag = 0;
          break;
        }
        x[i] = 1, y[j] = 1;
      }
    }
    if (!flag) break;
  }
  int p = 0, q = 0;
  for (int i = 0; i < n; i++)
    if (!x[i]) p = 1;
  for (int i = 0; i < m; i++)
    if (!y[i]) q = 1;
  if (p ^ q) flag = 0;
  if (!flag) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == '#') ans++, dfs(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}
