#include <bits/stdc++.h>
using namespace std;
int n, m;
string gr[1005];
int vis[1005][1005];
int visi[1005], visj[1005];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void go(int x, int y) {
  if (x < 0 || y < 0 || x >= n || y >= m) return;
  if (gr[x][y] == '.' || vis[x][y]) return;
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) go(x + dx[i], y + dy[i]);
}
int main() {
  cin >> n >> m;
  int anb = 0;
  for (int i = 0; i < n; i++) {
    cin >> gr[i];
    for (int j = 0; j < m; j++) {
      anb |= (gr[i][j] == '#');
      if (gr[i][j] == '#') visi[i] = 1, visj[j] = 1;
    }
  }
  int allis = 1, alljs = 1;
  for (int i = 0; i < n; i++) allis &= visi[i];
  for (int i = 0; i < m; i++) alljs &= visj[i];
  if (!anb) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    int got = -1;
    for (int j = 0; j < m; j++) {
      if (got == -1) {
        if (gr[i][j] == '#') got = 0;
      }
      if (got == 0) {
        if (gr[i][j] == '.') got = 1;
      }
      if (got == 1) {
        if (gr[i][j] == '#') {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    if (got == -1 && alljs) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    int got = -1;
    for (int j = 0; j < n; j++) {
      if (got == -1) {
        if (gr[j][i] == '#') got = 0;
      }
      if (got == 0) {
        if (gr[j][i] == '.') got = 1;
      }
      if (got == 1) {
        if (gr[j][i] == '#') {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    if (got == -1 && allis) {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (!vis[i][j] && gr[i][j] == '#') {
        ans++;
        go(i, j);
      }
    }
  }
  cout << ans << endl;
}
