#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <class T>
ostream& prnt(ostream& out, T v) {
  out << v.size() << '\n';
  for (auto e : v) out << e << ' ';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, vector<T> v) {
  return prnt(out, v);
}
template <class T>
ostream& operator<<(ostream& out, set<T> v) {
  return prnt(out, v);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, map<T1, T2> v) {
  return prnt(out, v);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  return out << '(' << p.first << ' ' << p.second << ')';
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
const long double PI = acos(-1);
int n, m, viz[1005][1005], R[1005], C[1005], emp;
char mat[1005][1005];
int dx[] = {0, 1, -1, 0};
int dy[] = {1, 0, 0, -1};
vector<pair<int, int> > H;
bool OK(int x, int y) {
  if (x < 1 || x > n) return 0;
  if (y < 1 || y > m) return 0;
  return 1;
}
void fill(int x, int y) {
  H.clear();
  H.push_back({x, y});
  for (int i = 0; i < H.size(); i++) {
    pair<int, int> crt = H[i];
    for (int k = 0; k < 4; k++) {
      int X = crt.first + dx[k];
      int Y = crt.second + dy[k];
      if (OK(X, Y) && mat[X][Y] == '#' && !viz[X][Y]) {
        viz[X][Y] = 1;
        H.push_back({X, Y});
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> mat[i] + 1;
  }
  int emp = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (mat[i][j] == '#') emp = 0;
    }
  if (emp) {
    cout << 0 << '\n';
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    int ok = 0;
    for (int j = 1; j <= m; j++) {
      if (mat[i][j] == '#') {
        if (ok == 2) {
          cout << "-1\n";
          return 0;
        } else {
          ok = 1;
        }
      } else {
        if (ok == 1) {
          ok = 2;
        }
      }
    }
  }
  for (int j = 1; j <= m; j++) {
    int ok = 0;
    for (int i = 1; i <= n; i++) {
      if (mat[i][j] == '#') {
        if (ok == 2) {
          cout << "-1\n";
          return 0;
        } else {
          ok = 1;
        }
      } else {
        if (ok == 1) {
          ok = 2;
        }
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (mat[i][j] == '#') {
        R[i] = 1;
        C[j] = 1;
      }
      if (mat[i][j] == '#' && !viz[i][j]) {
        fill(i, j);
        cnt++;
      }
    }
  }
  int nrr = 0, nrc = 0;
  for (int i = 1; i <= n; i++) {
    if (R[i] == 0) {
      nrr++;
    }
  }
  for (int j = 1; j <= m; j++) {
    if (C[j] == 0) {
      nrc++;
    }
  }
  if ((nrc != 0 && nrr == 0) || (nrr != 0 && nrc == 0)) {
    cout << "-1\n";
    return 0;
  }
  cout << cnt << '\n';
  return 0;
}
