#include <bits/stdc++.h>
using namespace std;
void sorted(vector<int> arr) { sort(arr.begin(), arr.end()); }
void coutarr(vector<int> arr) {
  int n = arr.size();
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
  cout << endl;
}
void coutarr2(vector<vector<int>> arr) {
  int n = arr.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < arr[i].size(); j++) cout << arr[i][j] << " ";
    cout << endl;
  }
}
vector<int> dirx = {1, -1, 0, 0};
vector<int> diry = {0, 0, -1, 1};
bool check(int x, int y, int n, int m) {
  if (x >= 0 and y >= 0 and x < n and y < m) return true;
  return false;
}
void dfs(vector<string> &s, int n, int m, int x, int y) {
  s[x][y] = '.';
  for (int i = 0; i < 4; i++)
    if (check(x + dirx[i], y + diry[i], n, m) and
        s[x + dirx[i]][y + diry[i]] == '#')
      dfs(s, n, m, x + dirx[i], y + diry[i]);
}
int count(vector<string> s, int n, int m) {
  int ct = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '#') {
        dfs(s, n, m, i, j);
        ct++;
      }
    }
  }
  return ct;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<string> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  bool flag = 0;
  for (int i = 0; i < n; i++) {
    bool flag1 = 0, flag2 = 0;
    for (int j = 0; j < m - 1; j++) {
      if (arr[i][j] == '#' and arr[i][j + 1] == '.') flag1 = 1;
      if (arr[i][j] == '.' and arr[i][j + 1] == '#' and flag1) flag2 = 1;
    }
    if (flag1 and flag2) {
      flag = 1;
      break;
    }
  }
  for (int j = 0; j < m; j++) {
    bool flag1 = 0, flag2 = 0;
    for (int i = 0; i < n - 1; i++) {
      if (arr[i][j] == '#' and arr[i + 1][j] == '.') flag1 = 1;
      if (arr[i][j] == '.' and arr[i + 1][j] == '#' and flag1) flag2 = 1;
    }
    if (flag1 and flag2) {
      flag = 1;
      break;
    }
  }
  bool flag3 = 0, flag4 = 0;
  for (int i = 0; i < n; i++) {
    bool flag1 = 1;
    for (int j = 0; j < m; j++) {
      if (arr[i][j] == '#') {
        flag1 = 0;
        break;
      }
    }
    if (flag1) {
      flag3 = 1;
      break;
    }
  }
  for (int j = 0; j < m; j++) {
    bool flag1 = 1;
    for (int i = 0; i < n; i++) {
      if (arr[i][j] == '#') {
        flag1 = 0;
        break;
      }
    }
    if (flag1) {
      flag4 = 1;
      break;
    }
  }
  if (flag or (flag3 and !flag4) or (flag4 and !flag3))
    cout << -1;
  else
    cout << count(arr, n, m);
  return 0;
}
