#include <bits/stdc++.h>
using namespace std;
long long n, m;
int t[1010][1010];
void f(int i, int j) {
  t[i][j] = 2;
  if (t[i + 1][j] == 1) f(i + 1, j);
  if (t[i - 1][j] == 1) f(i - 1, j);
  if (t[i][j + 1] == 1) f(i, j + 1);
  if (t[i][j - 1] == 1) f(i, j - 1);
}
int main() {
  cin >> n >> m;
  char c;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> c;
      if (c == '#') t[i][j] = 1;
    }
  }
  bool b = 1;
  int d = 0, e = 0;
  for (int i = 1; i <= n; ++i) {
    int a = 0;
    for (int j = 1; j <= m; ++j) {
      if (t[i][j] == 1) {
        if (a == 0)
          a = 1;
        else if (a == 2)
          b = 0;
      } else {
        if (a == 1) a = 2;
      }
    }
    if (a == 0) d = 1;
  }
  for (int i = 1; i <= m; ++i) {
    int a = 0;
    for (int j = 1; j <= n; ++j) {
      if (t[j][i] == 1) {
        if (a == 0)
          a = 1;
        else if (a == 2)
          b = 0;
      } else {
        if (a == 1) a = 2;
      }
    }
    if (a == 0) e = 1;
  }
  if (b == 0 || (d == 1 && e == 0) || (d == 0 && e == 1)) {
    cout << "-1\n";
  } else {
    int va = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        if (t[i][j] == 1) {
          f(i, j);
          va++;
        }
      }
    }
    cout << va << "\n";
  }
}
