#include <bits/stdc++.h>
using namespace std;
int n, m;
string grid[1002];
bool vis[1002][1002] = {};
int rep[1002][1002] = {};
bool is_black_present_row[1001] = {};
bool is_black_present_col[1001] = {};
int deli[] = {0, 1, 0, -1};
int delj[] = {1, 0, -1, 0};
int main() {
  int i, j;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> grid[i];
  }
  stack<pair<int, int>> dfs;
  int rep_no = 0;
  pair<int, int> u, v;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (vis[i][j] || grid[i][j] != '#') {
        continue;
      } else {
        rep_no++;
        vis[i][j] = 1;
        rep[i][j] = rep_no;
        dfs.push({i, j});
        while (!dfs.empty()) {
          u = dfs.top();
          dfs.pop();
          for (int k = 0; k < 4; k++) {
            v.first = u.first + deli[k];
            v.second = u.second + delj[k];
            if (v.first >= 0 && v.first < n && v.second >= 0 && v.second < m &&
                grid[v.first][v.second] == '#') {
              if (vis[v.first][v.second] == 0) {
                vis[v.first][v.second] = 1;
                dfs.push(v);
                rep[v.first][v.second] = rep_no;
              }
            }
          }
        }
      }
    }
  }
  bool prev_was_white;
  int count;
  for (i = 0; i < n; i++) {
    prev_was_white = 1;
    count = 0;
    for (j = 0; j < m; j++) {
      if (grid[i][j] == '#') {
        if (prev_was_white) count++;
        prev_was_white = 0;
        is_black_present_row[i] = 1;
      } else {
        prev_was_white = 1;
      }
    }
    if (count > 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (j = 0; j < m; j++) {
    prev_was_white = 1;
    count = 0;
    for (i = 0; i < n; i++) {
      if (grid[i][j] == '#') {
        if (prev_was_white) count++;
        prev_was_white = 0;
        is_black_present_col[j] = 1;
      } else {
        prev_was_white = 1;
      }
    }
    if (count > 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  bool flag = 0;
  for (i = 0; i < n; i++) {
    flag = 0;
    for (j = 0; j < m; j++) {
      if (grid[i][j] == '#') {
        flag = 1;
      } else {
        if (is_black_present_col[j] == 0) {
          flag = 1;
        }
      }
    }
    if (flag == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (j = 0; j < m; j++) {
    flag = 0;
    for (i = 0; i < n; i++) {
      if (grid[i][j] == '#') {
        flag = 1;
      } else {
        if (is_black_present_row[i] == 0) {
          flag = 1;
        }
      }
    }
    if (flag == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << rep_no << endl;
  return 0;
}
