#include <bits/stdc++.h>
using namespace std;
int n, m, a[1011][1011], par[1000011], rk[1000011],
    black = 0, dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int c_row[1011], c_col[1011], mark_row[1011], mark_col[1011], mark2_row[1011],
    mark2_col[1011];
int getId(int x, int y) { return (x - 1) * m + y; }
int findSet(int u) {
  if (par[u] == u) return u;
  return par[u] = findSet(par[u]);
}
bool isSameSet(int u, int v) { return findSet(u) == findSet(v); }
void Unite(int u, int v) {
  u = findSet(u), v = findSet(v);
  if (rk[u] < rk[v]) {
    par[u] = par[v];
  } else {
    par[v] = par[u];
    if (rk[u] == rk[v]) rk[u]++;
  }
  return;
}
bool valid_grid() {
  int N = n, M = m;
  for (int i = 1; i <= n; i++) {
    bool white = 0;
    int cnt = 0, row = 0;
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == 1) row++;
      c_row[i] = max(c_row[i], a[i][j]);
      c_col[j] = max(c_col[j], a[i][j]);
      if (a[i][j] == 1 && !white) {
        cnt++;
        white = 1;
      } else if (a[i][j] == 0) {
        white = 0;
      }
    }
    if (row == 0) mark_row[i] = 1;
    if (cnt >= 2) return 0;
  }
  for (int j = 1; j <= m; j++) {
    bool white = 0;
    int cnt = 0, col = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i][j] == 1) col++;
      if (a[i][j] == 1 && !white) {
        cnt++;
        white = 1;
      } else if (a[i][j] == 0) {
        white = 0;
      }
    }
    if (col == 0) mark_col[j] = 1;
    if (cnt >= 2) return 0;
  }
  bool yes = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mark_row[i] == 1 && mark_col[j] == 1) {
        mark2_row[i] = 1;
        mark2_col[i] = 1;
        yes = 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) N -= mark2_row[i];
  for (int j = 1; j <= m; j++) M -= mark2_col[j];
  int s1 = accumulate(c_row + 1, c_row + n + 1, 0),
      s2 = accumulate(c_col + 1, c_col + m + 1, 0);
  if (yes) return 1;
  if (s1 < N || s2 < M) return 0;
  return 1;
}
void connect(int x, int y) {
  if (a[x][y] == 0) return;
  for (int i = 0; i < 4; i++) {
    int u = x + dx[i], v = y + dy[i];
    if (a[u][v] == 1 && !isSameSet(getId(x, y), getId(u, v)))
      Unite(getId(x, y), getId(u, v));
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      char c;
      cin >> c;
      if (c == '#') {
        a[i][j]++;
        black++;
      }
      par[getId(i, j)] = getId(i, j);
    }
  if (black == n * m) {
    cout << 1;
    return 0;
  }
  if (black == 0) {
    cout << 0;
    return 0;
  }
  if (!valid_grid()) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      connect(i, j);
    }
  }
  set<int> ans;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == 1) ans.insert(findSet(getId(i, j)));
    }
  }
  cout << (int)ans.size();
  return 0;
}
