#include <bits/stdc++.h>
using namespace std;
const int MAX = 1001;
int n, m;
char board[MAX][MAX];
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};
bool vis[MAX][MAX];
void dfs(int r, int c) {
  vis[r][c] = 1;
  for (int i = 0; i < 4; i++) {
    int tr, tc;
    tr = r + dr[i];
    tc = c + dc[i];
    if (tr < 0 | tc < 0 | tr >= n | tc >= m | vis[tr][tc] |
        board[tr][tc] != '#')
      continue;
    dfs(tr, tc);
  }
}
int main() {
  cin >> n >> m;
  for (int r = 0; r < n; r++)
    for (int c = 0; c < m; c++) cin >> board[r][c];
  bool ans = 1;
  int rc = 0, cc = 0;
  for (int r = 0; r < n; r++) {
    bool is = 0;
    int before;
    for (int c = 0; c < m; c++)
      if (!is && board[r][c] == '#')
        is = 1, before = c;
      else if (is && board[r][c] == '#') {
        if (before + 1 != c) ans = 0;
        before = c;
      }
    rc += is;
  }
  for (int c = 0; c < m; c++) {
    bool is = 0;
    int before;
    for (int r = 0; r < n; r++)
      if (!is && board[r][c] == '#')
        is = 1, before = r;
      else if (is && board[r][c] == '#') {
        if (before + 1 != r) ans = 0;
        before = r;
      }
    cc += is;
  }
  if (cc == m && rc == n)
    ans &= 1;
  else if (cc == m | rc == n)
    ans = 0;
  if (ans) {
    int cnt = 0;
    for (int r = 0; r < n; r++)
      for (int c = 0; c < m; c++)
        if (!vis[r][c] && board[r][c] == '#') dfs(r, c), cnt++;
    cout << cnt;
  } else
    cout << -1;
  return 0;
}
