#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int num = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    num = (num << 3) + (num << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -num : num;
}
int n, m;
vector<int> c[1005], r[1005];
char ch[1005][1005];
bool vis[1005], vis2[1005];
int main() {
  n = read(), m = read();
  int numj = 0, numi = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> ch[i][j];
      if (ch[i][j] == '#') {
        c[i].push_back(j);
        r[j].push_back(i);
        if (!vis[j]) {
          numj++;
          vis[j] = true;
        }
        if (!vis2[i]) {
          vis2[i] = true;
          numi++;
        }
      }
    }
  }
  int tag;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (ch[i][j] == '.') {
        if (c[i].size()) {
          int len = c[i].size();
          if (j > c[i][len - 1] || j < c[i][0])
            tag = 1;
          else {
            cout << -1;
            return 0;
          }
        }
        if (r[j].size()) {
          int len = r[j].size();
          if (i > r[j][len - 1] || i < r[j][0])
            tag = 1;
          else {
            cout << -1;
            return 0;
          }
        }
      }
    }
  }
  int pre, aft, minl = 1005, maxl = 0, ans = 0, rest = 0;
  for (int i = 1; i <= n; i++) {
    pre = 0;
    for (int j = 1; j <= m; j++) {
      if (ch[i][j] == '#') {
        if (!pre) pre = j;
        if (j == m || ch[i][j + 1] == '.') aft = j;
      }
    }
    if (!pre) {
      rest++;
      continue;
    }
    if (minl == 0) {
      minl = pre;
      maxl = aft;
      ans++;
    } else if (pre > maxl) {
      ans++;
      minl = pre;
      maxl = aft;
    } else if (aft < minl) {
      minl = pre;
      maxl = aft;
      ans++;
    } else {
      maxl = max(maxl, aft);
      minl = min(minl, pre);
    }
  }
  if (numj == m && rest) {
    cout << -1;
    return 0;
  }
  rest = 0;
  for (int i = 1; i <= m; i++) {
    int flag = 0;
    for (int j = 1; j <= n; j++) {
      if (ch[j][i] == '#') {
        flag = 1;
        break;
      }
    }
    if (!flag && numi == n) {
      cout << -1;
      return 0;
    }
  }
  cout << ans;
  return 0;
}
