#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m, a[N][N];
bool visited[N][N];
int zbirc[N], zbirr[N];
bool ok(int i, int j) {
  return (i >= 1 && i <= n && j >= 1 && j <= m && a[i][j] && !visited[i][j]);
}
void dfs(int i, int j) {
  visited[i][j] = 1;
  if (ok(i + 1, j)) {
    dfs(i + 1, j);
  }
  if (ok(i - 1, j)) {
    dfs(i - 1, j);
  }
  if (ok(i, j + 1)) {
    dfs(i, j + 1);
  }
  if (ok(i, j - 1)) {
    dfs(i, j - 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= m; j++) {
      a[i][j] = (s[j - 1] == '#');
      zbirr[i] += a[i][j];
      zbirc[j] += a[i][j];
    }
  }
  bool imanulac = 0;
  for (int j = 1; j <= m; j++) {
    imanulac |= (zbirc[j] == 0);
  }
  bool imanular = 0;
  for (int i = 1; i <= n; i++) {
    imanular |= (zbirr[i] == 0);
  }
  for (int i = 1; i <= n; i++) {
    if (!zbirr[i] && !imanulac) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int j = 1; j <= m; j++) {
    if (!zbirc[j] && !imanular) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    int pos = 1;
    while (pos <= m && a[i][pos] == 0) {
      pos++;
    }
    bool bio1 = 0, bio0 = 0;
    for (int j = pos; j <= m; j++) {
      if (!a[i][j]) {
        bio0 = 1;
      } else {
        bio1 = 1;
      }
      if (bio0 && a[i][j] == 1) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  for (int j = 1; j <= m; j++) {
    int pos = 1;
    while (pos <= n && a[pos][j] == 0) {
      pos++;
    }
    bool bio1 = 0, bio0 = 0;
    for (int i = pos; i <= n; i++) {
      if (!a[i][j]) {
        bio0 = 1;
      } else {
        bio1 = 1;
      }
      if (bio0 && a[i][j] == 1) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] && !visited[i][j]) {
        cnt++;
        dfs(i, j);
      }
    }
  }
  cout << cnt << endl;
}
