#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << ',' << p.second;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<string> f(n);
  cin >> f;
  auto g = f;
  for (int i = 0; i < n; i++) {
    int state = 0;
    int l = 0, r = m;
    for (int j = 0; j < m; j++) {
      if (state == 0 && f[i][j] == '#') {
        l = j;
        state = 1;
      }
      if (state == 1 && f[i][j] == '.') {
        r = j;
        state = 2;
      }
      if (state == 2 && f[i][j] == '#') {
        cout << -1 << "\n";
        return;
      }
    }
    for (int j = 0; j < l; j++) {
      g[i][j] = 'z';
    }
    for (int j = r; j < m; j++) {
      g[i][j] = 'z';
    }
  }
  for (int i = 0; i < m; i++) {
    int state = 0;
    int l = 0, r = n;
    for (int j = 0; j < n; j++) {
      if (state == 0 && f[j][i] == '#') {
        l = j;
        state = 1;
      }
      if (state == 1 && f[j][i] == '.') {
        r = j;
        state = 2;
      }
      if (state == 2 && f[j][i] == '#') {
        cout << -1 << "\n";
        return;
      }
    }
    for (int j = 0; j < l; j++) {
      g[j][i] = 'z';
    }
    for (int j = r; j < n; j++) {
      g[j][i] = 'z';
    }
  }
  for (int i = 0; i < n; i++) {
    bool judge = false;
    for (int j = 0; j < m; j++) {
      if (g[i][j] != 'z') judge = true;
    }
    if (!judge) {
      cout << -1 << "\n";
      return;
    }
  }
  for (int i = 0; i < m; i++) {
    bool judge = false;
    for (int j = 0; j < n; j++) {
      if (g[j][i] != 'z') judge = true;
    }
    if (!judge) {
      cout << -1 << "\n";
      return;
    }
  }
  vector<vector<bool>> visited = vect(n, vect(m, false));
  vector<int> dx = {0, 1, 0, -1};
  vector<int> dy = {1, 0, -1, 0};
  function<void(int, int)> dfs = [&](int x, int y) {
    visited[x][y] = true;
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx < 0 || ny < 0 || nx >= n || ny >= m) continue;
      if (f[nx][ny] != '#') continue;
      if (visited[nx][ny]) continue;
      dfs(nx, ny);
    }
  };
  int cmp = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (f[i][j] == '#' && !visited[i][j]) {
        dfs(i, j);
        cmp++;
      }
    }
  }
  cout << cmp << "\n";
  return;
}
signed main() {
  fastio();
  solve();
  return 0;
}
