#include <bits/stdc++.h>
using namespace std;
char a[1001][1001];
int vis[1001][1001];
int n, m;
void dfs(int x, int y) {
  vis[x][y] = 1;
  if (x - 1 >= 0 && !vis[x - 1][y] && a[x - 1][y] == '#') {
    dfs(x - 1, y);
  }
  if (x + 1 < n && !vis[x + 1][y] && a[x + 1][y] == '#') {
    dfs(x + 1, y);
  }
  if (y - 1 >= 0 && !vis[x][y - 1] && a[x][y - 1] == '#') {
    dfs(x, y - 1);
  }
  if (y + 1 < m && !vis[x][y + 1] && a[x][y + 1] == '#') {
    dfs(x, y + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  int f1 = 0, f2 = 0, f3 = 0;
  int awr = 0, awc = 0, c = 0, ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (!f1 && a[i][j] == '#') {
        f1 = 1;
      } else if (f1 && !f2 && a[i][j] == '.') {
        f2 = 1;
      } else if (f1 && f2 && !f3 && a[i][j] == '#') {
        f3 = 1;
      }
    }
    if (f1 && f2 && f3) {
      cout << "-1\n";
      goto here;
    } else {
      f1 = f2 = f3 = 0;
    }
  }
  for (int j = 0; j < m; ++j) {
    for (int i = 0; i < n; ++i) {
      if (!f1 && a[i][j] == '#') {
        f1 = 1;
      } else if (f1 && !f2 && a[i][j] == '.') {
        f2 = 1;
      } else if (f1 && f2 && !f3 && a[i][j] == '#') {
        f3 = 1;
      }
    }
    if (f1 && f2 && f3) {
      cout << "-1\n";
      goto here;
    } else {
      f1 = f2 = f3 = 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    c = 0;
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '.') {
        c++;
      }
    }
    if (c == m) {
      awr = 1;
      break;
    }
  }
  for (int j = 0; j < m; ++j) {
    c = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i][j] == '.') {
        c++;
      }
    }
    if (c == n) {
      awc = 1;
      break;
    }
  }
  if (awr ^ awc) {
    cout << "-1\n";
    goto here;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '#' && !vis[i][j]) {
        ans++;
        dfs(i, j);
      }
    }
  }
  cout << ans << "\n";
here:;
}
