#include <bits/stdc++.h>
using namespace std;
template <typename T>
T sgn(T x) {
  return x < 0 ? -1 : (x > 0 ? 1 : 0);
}
template <typename T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <typename T>
T abs(T x) {
  return x < 0 ? -x : x;
}
template <typename T>
T sqr(T x) {
  return x * x;
}
int n, m, pai[((int)1e3 + 123) * ((int)1e3 + 123)], last[((int)1e3 + 123)],
    pode, row, col;
int valor(int i, int j) { return i * m + j; }
void inicia() {
  for (int i = 0; i <= n * m; i++) pai[i] = i;
}
int id(int u) { return pai[u] = (u == pai[u] ? u : id(pai[u])); }
void unir(int u, int v) {
  u = id(u), v = id(v);
  pai[u] = v;
}
string s[((int)1e3 + 123)];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  inicia();
  pode = 1;
  memset(last, -1, sizeof last);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    int ult = -1;
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.' || !pode) continue;
      if ((ult != -1 && j - ult != 1) || (last[j] != -1 && i - last[j] != 1)) {
        pode = 0;
        continue;
      }
      if (i > 0 && s[i - 1][j] == '#') unir(valor(i - 1, j), valor(i, j));
      if (j > 0 && s[i][j - 1] == '#') unir(valor(i, j - 1), valor(i, j));
      ult = j;
      last[j] = i;
    }
    if (ult == -1) row = 1;
  }
  for (int j = 0; j < m; j++)
    if (last[j] == -1) col = 1;
  if (row ^ col) pode = 0;
  if (pode) {
    set<int> vals;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        if (s[i][j] == '#') vals.insert(id(valor(i, j)));
      }
    cout << (int)vals.size() << "\n";
  } else
    cout << -1 << "\n";
}
