#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
const int inf = 0x7ffffff;
int vis[maxn][maxn];
char s[maxn][maxn];
int dx[] = {0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0};
int n, m;
void bfs(int px, int py) {
  queue<pair<int, int>> que;
  que.push({px, py});
  pair<int, int> tp;
  int tx, ty;
  vis[px][py] = 1;
  while (!que.empty()) {
    tp = que.front(), que.pop();
    for (int i = 0; i < 4; i++) {
      tx = tp.first + dx[i];
      ty = tp.second + dy[i];
      if (tx > 0 && tx <= n && ty > 0 && ty <= m && !vis[tx][ty] &&
          s[tx][ty] == '#') {
        vis[tx][ty] = 1;
        que.push({tx, ty});
      }
    }
  }
}
int row[maxn], col[maxn];
void solve() {
  cin >> n >> m;
  memset(vis, 0, sizeof(vis)), memset(row, 0, sizeof(row)),
      memset(col, 0, sizeof(col));
  for (int i = 1; i <= n; i++) {
    cin >> (s[i] + 1);
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#') row[i]++, col[j]++;
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!vis[i][j] && s[i][j] == '#') bfs(i, j), cnt++;
    }
  }
  int fla = 0;
  for (int i = 1; i <= n; i++) {
    fla = 0;
    if (row[i] == 0) {
      for (int j = 1; j <= m; j++) {
        if (col[j] == 0) {
          fla = 1;
          break;
        }
      }
      if (!fla) {
        cout << "-1\n";
        return;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    fla = 0;
    if (col[i] == 0) {
      for (int j = 1; j <= n; j++) {
        if (row[j] == 0) {
          fla = 1;
          break;
        }
      }
      if (!fla) {
        cout << "-1\n";
        return;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int left, right;
    left = m + 1, right = 0;
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == '#') {
        left = min(j, left);
        right = max(j, right);
      }
    }
    for (int k = left; k <= right; k++) {
      if (s[i][k] == '.') {
        cout << "-1\n";
        return;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    int left, right;
    left = n + 1, right = 0;
    for (int j = 1; j <= n; j++) {
      if (s[j][i] == '#') {
        left = min(j, left);
        right = max(j, right);
      }
    }
    for (int k = left; k <= right; k++) {
      if (s[k][i] == '.') {
        cout << "-1\n";
        return;
      }
    }
  }
  cout << cnt << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  while (T-- > 0) solve();
}
