#include <bits/stdc++.h>
using namespace std;
const int maxp = 22;
const long double EPS = 1e-18;
const long long INF = 2e18;
const int MOD = 1e9 + 7;
const int N = 1e3 + 1;
bool arr[N][N], v[N][N];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void dfs(int x, int y) {
  v[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx >= 0 && ny >= 0 && arr[nx][ny] && !v[nx][ny]) dfs(nx, ny);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int i, j;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      char c;
      cin >> c;
      if (c == '#')
        arr[i][j] = 1;
      else
        arr[i][j] = 0;
    }
  bool flag = false;
  bool p1 = false, p2 = false;
  for (i = 0; i < n; i++) {
    int j = 0;
    bool f = false;
    while (j < m) {
      if (arr[i][j]) {
        if (f) {
          flag = true;
          break;
        } else {
          f = true;
          while (j < m && arr[i][j]) j++;
        }
      } else
        j++;
    }
    if (!f) p1 = true;
  }
  for (j = 0; j < m; j++) {
    int i = 0;
    bool f = false;
    while (i < n) {
      if (arr[i][j]) {
        if (f) {
          flag = true;
          break;
        } else {
          f = true;
          while (i < n && arr[i][j]) i++;
        }
      } else
        i++;
    }
    if (!f) p2 = true;
  }
  if (flag || p1 ^ p2) {
    cout << -1 << '\n';
    return 0;
  }
  int ans = 0;
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      if (v[i][j] || !arr[i][j]) continue;
      ans++;
      dfs(i, j);
    }
  cout << ans;
}
