#include <bits/stdc++.h>
const int MOD = 998244353;
const int INF = 1e9 + 7;
using namespace std;
inline long long read();
int n, m;
bool col[1010], row[1010];
int pre[1010 * 1010];
bool vis[1010 * 1010];
char ch[1010][1010];
void init() {
  for (int i = 0; i < 1010; i++) col[i] = 1, row[i] = 1;
  memset(vis, false, sizeof(vis));
}
int find(int r) {
  int rt = r;
  while (r != pre[r]) r = pre[r];
  while (rt != r) {
    int tmp = pre[rt];
    pre[rt] = r;
    rt = tmp;
  }
  return r;
}
void join(int x, int y) {
  x = find(x);
  y = find(y);
  if (x != y) pre[x] = y;
}
int main() {
  init();
  n = read(), m = read();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> ch[i][j];
      pre[(i - 1) * m + j] = (i - 1) * m + j;
      if (ch[i][j] == '#') row[i] = 0, col[j] = 0;
    }
  for (int i = 1; i <= n; i++) {
    int flag = 1;
    for (int j = 2; j <= m; j++) {
      if (flag == 1 && ch[i][j - 1] == '#' && ch[i][j] == '.') flag = 2;
      if (flag == 2 && ch[i][j - 1] == '.' && ch[i][j] == '#') {
        puts("-1");
        return 0;
      }
    }
  }
  for (int j = 1; j <= m; j++) {
    int flag = 1;
    for (int i = 2; i <= n; i++) {
      if (flag == 1 && ch[i - 1][j] == '#' && ch[i][j] == '.') flag = 2;
      if (flag == 2 && ch[i - 1][j] == '.' && ch[i][j] == '#') {
        puts("-1");
        return 0;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (row[i]) {
      bool flag = false;
      for (int j = 1; j <= m; j++)
        if (col[j]) {
          flag = true;
          break;
        }
      if (!flag) {
        puts("-1");
        return 0;
      }
    }
  }
  for (int j = 1; j <= m; j++) {
    if (col[j]) {
      bool flag = false;
      for (int i = 1; i <= n; i++)
        if (row[i]) {
          flag = true;
          break;
        }
      if (!flag) {
        puts("-1");
        return 0;
      }
    }
  }
  vis[0] = true;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (ch[i][j] == '.') pre[(i - 1) * m + j] = 0;
      if (ch[i][j] == '#') {
        if (ch[i - 1][j] == '#') join((i - 1) * m + j, (i - 2) * m + j);
        if (ch[i][j - 1] == '#') join((i - 1) * m + j, (i - 1) * m + j - 1);
      }
    }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int x = find((i - 1) * m + j);
      if (!vis[x]) cnt++;
      vis[x] = true;
    }
  cout << cnt;
  return 0;
}
inline long long read() {
  long long p = 1, ans = 0;
  char ch = getchar();
  while (ch < 48 || ch > 57) {
    if (ch == '-') p = -1;
    ch = getchar();
  }
  while (ch >= 48 && ch <= 57) {
    ans = (ans << 3) + (ans << 1) + ch - 48;
    ch = getchar();
  }
  return ans * p;
}
