#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
char mt[1010][1010];
char pv[1010][1010];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", mt[i]);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      bool can = true;
      int k;
      k = 0;
      while (k < i and mt[k][j] == '.') ++k;
      if (mt[k][j] == '#')
        while (k <= i)
          if (mt[k++][j] == '.') can = false;
      k = n - 1;
      while (k > i and mt[k][j] == '.') --k;
      if (mt[k][j] == '#')
        while (k >= i)
          if (mt[k--][j] == '.') can = false;
      k = 0;
      while (k < j and mt[i][k] == '.') ++k;
      if (mt[i][k] == '#')
        while (k <= j)
          if (mt[i][k++] == '.') can = false;
      k = m - 1;
      while (k > j and mt[i][k] == '.') --k;
      if (mt[i][k] == '#')
        while (k >= j)
          if (mt[i][k--] == '.') can = false;
      if (can)
        pv[i][j] = 'S';
      else
        pv[i][j] = '#';
    }
    pv[n][m] = '\0';
  }
  bool can = true;
  for (int i = 0; i < n; ++i) {
    bool flag = false;
    for (int j = 0; j < m; ++j)
      if (pv[i][j] == 'S') {
        flag = true;
        break;
      }
    if (not flag) {
      can = false;
      break;
    }
  }
  for (int j = 0; j < m; ++j) {
    bool flag = false;
    for (int i = 0; i < n; ++i)
      if (pv[i][j] == 'S') {
        flag = true;
        break;
      }
    if (not flag) {
      can = false;
      break;
    }
  }
  if (not can) {
    printf("-1\n");
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (mt[i][j] == '.') continue;
      ++ans;
      queue<ii> q;
      q.push({i, j});
      mt[i][j] = '#';
      while (not q.empty()) {
        int _i = q.front().first;
        int _j = q.front().second;
        q.pop();
        if (_i - 1 >= 0 and mt[_i - 1][_j] == '#')
          q.push({_i - 1, _j}), mt[_i - 1][_j] = '.';
        if (_i + 1 < n and mt[_i + 1][_j] == '#')
          q.push({_i + 1, _j}), mt[_i + 1][_j] = '.';
        if (_j - 1 >= 0 and mt[_i][_j - 1] == '#')
          q.push({_i, _j - 1}), mt[_i][_j - 1] = '.';
        if (_j + 1 < m and mt[_i][_j + 1] == '#')
          q.push({_i, _j + 1}), mt[_i][_j + 1] = '.';
      }
    }
  }
  printf("%d\n", ans);
}
