#include <bits/stdc++.h>
using namespace std;
char forbidden = '.';
char required = '#';
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<string> grid(n);
  for (long long i = 0; i < n; i++) {
    cin >> grid[i];
  }
  bool unusedRows = false;
  for (long long i = 0; i < n; i++) {
    bool entered = false;
    bool left = false;
    for (long long j = 0; j < m; j++) {
      if (grid[i][j] == required) {
        entered = true;
        if (left) {
          cout << "-1\n";
          return 0;
        }
      } else {
        if (entered) left = true;
      }
    }
    if (!entered) {
      unusedRows = true;
    }
  }
  bool unusedCols = false;
  for (long long j = 0; j < m; j++) {
    bool entered = false;
    bool left = false;
    for (long long i = 0; i < n; i++) {
      if (grid[i][j] == required) {
        entered = true;
        if (left) {
          cout << "-1\n";
          return 0;
        }
      } else {
        if (entered) left = true;
      }
    }
    if (!entered) {
      unusedCols = true;
    }
  }
  if (unusedCols ^ unusedRows) {
    cout << "-1\n";
    return 0;
  }
  long long cnt = 0;
  {
    long long i = 0;
    bool hasRequired = false;
    for (long long j = 0; j < m; j++) {
      if (grid[i][j] == required) hasRequired = true;
    }
    if (hasRequired) cnt++;
  }
  for (long long i = 1; i < n; i++) {
    long long new_mag = true;
    long long hasRequired = false;
    for (long long j = 0; j < m; j++) {
      if (grid[i][j] == required) hasRequired = true;
      if (grid[i][j] == required && grid[i - 1][j] == required) {
        new_mag = false;
      }
    }
    if (new_mag && hasRequired) cnt++;
  }
  cout << cnt << "\n";
}
