#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

struct unionfind{
    vector<int> parent;
    vector<int> rank;
    vector<int> size;

    unionfind (int N) {
        parent = vector<int>(N);
        iota(parent.begin(), parent.end(), 0);
        rank = vector<int>(N, 0);
        size = vector<int>(N, 1);
    }
    int root(int x) {
        if (parent[x] == x) return x;
        parent[x] = root(parent[x]);
        return parent[x];
    }
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
        }
        else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) rank[y] += 1;
        }
    }
    
    int getsize(int x) {
        return size[root(x)];
    }
};

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> grid(H);
    for (int i = 0; i < H; i++) cin >> grid[i];
    unionfind uf(H+W);
    uf.unite(0, H);
    uf.unite(H-1, H);
    uf.unite(0, H+W-1);
    uf.unite(H-1, H+W-1);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '#') {
                uf.unite(i, H+j);
            }
        }
    }
    int ans = 0;
    int x = 0, y = 0;
    for (int i = 0; i < H+W; i++) {
        if (uf.root(i) == i) ans++;
        if (uf.getsize(i) == 1) {
            if (i < H) x++;
            else y++;
        }
    }
    cout << ans-max(x, y)-1 << endl;
    return 0;
}
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
using P = pair<int, int>;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i, m)cin >>a[i];
  sort(a.begin(), a.end());
  a.push_back(n + 1);
  int car =1;
  vector<int>s;
  rep(i, m + 1)
  {
    int w = a[i] - car;
    if (w != 0)
      s.push_back(w);
    car = a[i] + 1;
  }
  int k = n;
  for (int w : s)
    k = min(k, w);
int ans=0;
  for (int w : s)
    ans += (w + k - 1) / k;

  cout << ans << endl;

  return 0;
}
