#include <bits/stdc++.h>
using namespace std;
int power(long long int x, long long int y) {
  long long int temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
bool prime_check(long long int n) {
  long long int i, j;
  if (n == 1) {
    return false;
  }
  for (i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long int fact(long long int n) {
  long long int prod = 1;
  for (long long int i = 1; i <= n; i++) {
    prod = (prod * i) % 1000000007;
  }
  return prod;
}
bool vowl(char c) {
  return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
const int MAX = 100000;
const int MIN = -100000;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
string grid[1002];
bool vis[1002][1002];
int n, m;
bool check(int x, int y) {
  if (x >= 1 && x <= n && y >= 1 && y <= m && grid[x][y] == '#' && !vis[x][y])
    return true;
  return false;
}
void dfs(int x, int y) {
  vis[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int new_x = x + dx[i];
    int new_y = y + dy[i];
    if (check(new_x, new_y)) dfs(new_x, new_y);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int i, j;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> grid[i];
    grid[i] = '*' + grid[i];
  }
  bool WRow = false, WCol = false;
  for (i = 1; i <= n; i++) {
    int mini = MAX;
    int maxi = MIN;
    int cnt = 0;
    for (j = 1; j <= m; j++) {
      if (grid[i][j] == '#') {
        mini = min(mini, j);
        maxi = max(maxi, j);
        cnt++;
      }
    }
    if (mini == MAX)
      WRow = true;
    else if (maxi - mini + 1 != cnt) {
      cout << -1 << "\n";
      return 0;
    }
  }
  for (j = 1; j <= m; j++) {
    int mini = MAX;
    int maxi = MIN;
    int cnt = 0;
    for (i = 1; i <= n; i++) {
      if (grid[i][j] == '#') {
        mini = min(mini, i);
        maxi = max(maxi, i);
        cnt++;
      }
    }
    if (mini == MAX)
      WCol = true;
    else if (maxi - mini + 1 != cnt) {
      cout << -1 << "\n";
      return 0;
    }
  }
  if ((!WCol && WRow) || (WCol && !WRow)) {
    cout << -1 << "\n";
    return 0;
  }
  memset(vis, false, sizeof(vis));
  int count = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (grid[i][j] == '#' && !vis[i][j]) {
        dfs(i, j);
        count++;
      }
    }
  }
  cout << count << "\n";
  return 0;
}
