#include <bits/stdc++.h>
using namespace std;
const int64_t inf = 2e18;
int64_t inp() {
  int64_t x;
  cin >> x;
  return x;
}
string inp_str() {
  string x;
  cin >> x;
  return x;
}
int64_t sqr(int64_t n) { return n * n; }
int64_t power(int64_t a, int64_t b, int64_t mod) {
  int64_t res = 1;
  a %= mod;
  for (int64_t i = (0); i <= (log2(b)); ++i) {
    if (b & (1 << i)) res = (res * a) % mod;
    a = (a * a) % mod;
  }
  return res;
}
int64_t gcd(int64_t a, int64_t b) {
  while (b > 0) {
    int64_t tmp = a % b;
    a = b;
    b = tmp;
  }
  return a;
}
bool is_pal(string s) { return equal(begin(s), end(s), s.rbegin()); }
void fast_io() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
void file_io(char *in, char *out) {
  freopen(in, "r", stdin);
  freopen(out, "w", stdout);
}
void print_bool(bool a) {
  if (a)
    cout << "YES\n";
  else
    cout << "NO\n";
}
int64_t n, m;
vector<string> a;
vector<pair<int64_t, int64_t> > nxt = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
vector<vector<int64_t> > visited;
void Input() {
  n = inp(), m = inp();
  a.resize(n);
  visited.assign(n, vector<int64_t>(m, 0));
  for (int64_t i = (0); i <= (n - 1); ++i) a[i] = inp_str();
}
bool valid(int64_t i, int64_t j) {
  return i >= 0 && i < n && j >= 0 && j < m && a[i][j] == '#';
}
void Fill(int64_t i, int64_t j) {
  visited[i][j] = true;
  for (auto p : nxt) {
    int64_t x = i + p.first, y = j + p.second;
    if (valid(x, y) && !visited[x][y]) Fill(x, y);
  }
}
int64_t count_component() {
  int64_t res = 0;
  for (int64_t i = (0); i <= (n - 1); ++i)
    for (int64_t j = (0); j <= (m - 1); ++j)
      if (a[i][j] == '#' && !visited[i][j]) Fill(i, j), res++;
  return res;
}
bool possible() {
  int64_t allWhiteCol = 0, allWhiteRow = 0;
  bool oneSegment = true;
  for (int64_t i = (0); i <= (n - 1); ++i) {
    bool allWhite = true;
    int64_t segment = 0;
    for (int64_t j = (0); j <= (m - 1); ++j) {
      allWhite &= a[i][j] == '.';
      if (a[i][j] == '#' && (j == 0 || a[i][j - 1] == '.')) segment++;
    }
    allWhiteRow += allWhite;
    oneSegment &= segment <= 1;
  }
  for (int64_t i = (0); i <= (m - 1); ++i) {
    bool allWhite = true;
    int64_t segment = 0;
    for (int64_t j = (0); j <= (n - 1); ++j) {
      allWhite &= a[j][i] == '.';
      if (a[j][i] == '#' && (j == 0 || a[j - 1][i] == '.')) segment++;
    }
    allWhiteCol += allWhite;
    oneSegment &= segment <= 1;
  }
  return ((allWhiteCol + allWhiteRow == 0 || allWhiteCol * allWhiteRow > 0) &&
          oneSegment);
}
void Solve() {
  if (possible()) {
    int64_t ans = count_component();
    cout << ans << '\n';
  } else
    cout << -1;
}
int main() {
  fast_io();
  Input(), Solve();
  return 0;
}
