#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll mod = 1e9 + 7;
const double eps = 1e-9;
int n, m;
char g[1100][1100];
bool used[1100][1100];
bool whitecol[1100];
bool whiterow[1100];
void dfs(int i, int j) {
  if (!used[i][j] && g[i][j] == '#') {
    used[i][j] = true;
    if (i - 1 >= 0) dfs(i - 1, j);
    if (j + 1 < m) dfs(i, j + 1);
    if (i + 1 < n) dfs(i + 1, j);
    if (j - 1 >= 0) dfs(i, j - 1);
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < max(n, m); i++) {
    whitecol[i] = true;
    whiterow[i] = true;
  }
  for (int i = 0; i < n; i++) cin >> g[i];
  for (int i = 0; i < n; i++) {
    int l = 1e9, r = -1e9, cnt = 0;
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '#') {
        whiterow[i] = false;
        whitecol[j] = false;
        cnt++;
        l = min(l, j);
        r = j;
      }
    }
    if (cnt && cnt != r - l + 1) {
      cout << "-1\n";
      return;
    }
  }
  for (int j = 0; j < m; j++) {
    int u = 1e9, d = -1e9, cnt = 0;
    for (int i = 0; i < n; i++) {
      if (g[i][j] == '#') {
        cnt++;
        u = min(i, u);
        d = i;
      }
    }
    if (cnt && cnt != d - u + 1) {
      cout << "-1\n";
      return;
    }
  }
  for (int i = 0; i < n; i++) {
    if (whiterow[i]) {
      bool chk = false;
      for (int j = 0; j < m; j++) {
        if (whitecol[j]) chk = true;
      }
      if (!chk) {
        cout << "-1\n";
        return;
      }
    }
  }
  for (int j = 0; j < m; j++) {
    if (whitecol[j]) {
      bool chk = false;
      for (int i = 0; i < n; i++) {
        if (whiterow[i]) chk = true;
      }
      if (!chk) {
        cout << "-1\n";
        return;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == '#' && !used[i][j]) {
        ans++;
        dfs(i, j);
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
