#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
void __print(long long int x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename Th, typename V>
void __print(const pair<Th, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename Th>
void __print(const Th &x) {
  long long int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename Th, typename... V>
void _print(Th t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
long long int n, m;
long long int a[1005][1005];
long long int vis[1005][1005];
long long int con;
long long int valid(long long int i, long long int j) {
  if (i >= 0 && i < n && j >= 0 && j < m) {
    return 1;
  }
  return 0;
}
void dfs(long long int i, long long int j) {
  if (valid(i + 1, j) == 1) {
    if (a[i + 1][j] == 1) {
      if (vis[i + 1][j] == -1) {
        vis[i + 1][j] = con;
        dfs(i + 1, j);
      }
    }
  }
  if (valid(i - 1, j) == 1) {
    if (a[i - 1][j] == 1) {
      if (vis[i - 1][j] == -1) {
        vis[i - 1][j] = con;
        dfs(i - 1, j);
      }
    }
  }
  if (valid(i, j + 1) == 1) {
    if (a[i][j + 1] == 1) {
      if (vis[i][j + 1] == -1) {
        vis[i][j + 1] = con;
        dfs(i, j + 1);
      }
    }
  }
  if (valid(i, j - 1) == 1) {
    if (a[i][j - 1] == 1) {
      if (vis[i][j - 1] == -1) {
        vis[i][j - 1] = con;
        dfs(i, j - 1);
      }
    }
  }
}
void binary_rock() {
  cin >> n >> m;
  long long int i, j, k, l;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      char x;
      cin >> x;
      if (x == '#') {
        a[i][j] = 1;
      } else {
        a[i][j] = 0;
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      vis[i][j] = -1;
      if (a[i][j] == 0) vis[i][j] = -2;
    }
  }
  con = 0;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (vis[i][j] == -1) {
        if (a[i][j] == 1) {
          vis[i][j] = con;
          dfs(i, j);
          con++;
        }
      }
    }
  }
  long long int sum[m];
  for (i = 0; i < m; i++) {
    sum[i] = 0;
    for (j = 0; j < n; j++) sum[i] += a[j][i];
  }
  long long int row[n];
  for (i = 0; i < n; i++) {
    row[i] = 0;
    for (j = 0; j < m; j++) row[i] += a[i][j];
  }
  for (i = 0; i < n; i++) {
    long long int yeh = 0;
    for (j = 0; j < m; j++) {
      if (a[i][j] == 1) yeh = 1;
      if (sum[j] == 0) yeh = 1;
    }
    if (yeh == 0) {
      cout << "-1" << endl;
      return;
    }
  }
  for (i = 0; i < m; i++) {
    long long int yeh = 0;
    for (j = 0; j < n; j++) {
      if (a[j][i] == 1) yeh = 1;
      if (row[j] == 0) yeh = 1;
    }
    if (yeh == 0) {
      cout << "-1" << endl;
      return;
    }
  }
  for (i = 0; i < n; i++) {
    set<long long int> s;
    set<long long int> ch;
    for (j = 0; j < m; j++) {
      if (vis[i][j] != -2) {
        s.insert(vis[i][j]);
        ch.insert(j);
      }
    }
    if (s.size() == 0) continue;
    if (s.size() != 1) {
      cout << "-1" << endl;
      return;
    }
    long long int sz = ch.size();
    long long int fir = *(ch.begin());
    auto it = ch.end();
    it--;
    long long int las = ((*it));
    if ((las - fir + 1) != sz) {
      cout << "-1" << endl;
      return;
    }
  }
  for (i = 0; i < m; i++) {
    set<long long int> s;
    set<long long int> ch;
    for (j = 0; j < n; j++) {
      if (vis[j][i] != -2) {
        s.insert(vis[j][i]);
        ch.insert(j);
      }
    }
    if (s.size() == 0) continue;
    if (s.size() != 1) {
      cout << "-1" << endl;
      return;
    }
    long long int sz = ch.size();
    long long int fir = *(ch.begin());
    auto it = ch.end();
    it--;
    long long int las = ((*it));
    if ((las - fir + 1) != sz) {
      cout << "-1" << endl;
      return;
    }
  }
  cout << con << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  clock_t t1 = clock();
  long long int t = 1;
  while (t--) {
    binary_rock();
  }
  clock_t t2 = clock();
  return 0;
}
