#include <bits/stdc++.h>
using namespace std;
const long long N = 1001;
const long long MOD = 1000000007;
const long long INF = LLONG_MAX;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m;
vector<string> s;
bool vis[N][N];
bool isvalid(int x, int y) {
  return (x >= 0 && x < n && y >= 0 && y < m && s[x][y] == '#');
}
void dfs(int x, int y) {
  vis[x][y] = true;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (isvalid(nx, ny) && !vis[nx][ny]) dfs(nx, ny);
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  int tc = 1, cs = 0;
  while (tc--) {
    int i, j, ans = 0, r = 0, c = 0;
    cin >> n >> m;
    s.resize(n);
    for (i = 0; i < n; i++) cin >> s[i];
    for (i = 0; i < n; i++) {
      int cnt = 0, f = -1, l = 0;
      for (j = 0; j < m; j++)
        if (s[i][j] == '#') {
          cnt++;
          if (f == -1) f = j;
          l = j;
        }
      if (cnt == 0)
        r++;
      else if (l - f + 1 != cnt)
        return cout << -1 << '\n', 0;
    }
    for (j = 0; j < m; j++) {
      int cnt = 0, f = -1, l = 0;
      for (i = 0; i < n; i++)
        if (s[i][j] == '#') {
          cnt++;
          if (f == -1) f = i;
          l = i;
        }
      if (cnt == 0)
        c++;
      else if (l - f + 1 != cnt)
        return cout << -1 << '\n', 0;
    }
    if (r == n && c == m) return cout << 0 << '\n', 0;
    if ((r && c == 0) || (c && r == 0)) return cout << -1 << '\n', 0;
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++)
        if (!vis[i][j] && s[i][j] == '#') ans++, dfs(i, j);
    cout << ans << '\n';
  }
}
