[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
mnx=8000009
mod=1000000007
dx=array of 4 long long filled with -1, 0, 0, 1
dy=array of 4 long long filled with 0, -1, 1, 0
n,m=long long
s=array of 111 by 111 char
u=array of 111 by 111 bool
function check (get long long x and y, return bool)
    return 0 < x and x < n+1 and 0 < y and y < m+1
end of the block
function dfs (get long long x and y, return nothing)
    if u[x][y] return
    u[x][y]=true
    for i=0 to 4 exclusive
        if check(x+dx[i], y+dy[i]) and s[x+dx[i]][y+dy[i]] is '#' dfs(x+dx[i], y+dy[i])
    end of the block
end of the block
define the main function
    read n,m
    for i=1 to n inclusive
        for j=1 to m inclusive read s[i][j]
    end of the block
    qwe=0
    for i=1 to n inclusive
        for j=1 to m inclusive
            if s[i][j] is '#' increment qwe
        end of the block
    end of the block
    res=11111111111111
    for i=1 to n inclusive
        for j=1 to m inclusive
            if s[i][j] is '#'
                q=0
                for k=0 to 4 exclusive
                    if check(i+dx[k], j+dy[k]) and s[i+dx[k]][j+dy[k]] is '#' increment q
                end of the block
                if q+1 < qwe res=min(res, q)
                if qwe>1
                    s[i][j]='0'
                    for k=1 to n inclusive
                        for l=1 to m inclusive u[k][l]=false
                    end of the block
                    cnt=0
                    for k=1 to n inclusive
                        for l=1 to m inclusive
                            if s[k][l] is '#' and not u[k][l]
                                dfs(k,l)
                                increment cnt
                            end of the block
                        end of the block
                    end of the block
                    if cnt>1 res=min(res, 1)
                    s[i][j]='#'
                end of the block
            end of the block
        end of the block
    end of the block
    if res is 11111111111111 subtract 11111111111112 from res
    print res
    return to indicate successful execution
end of the block

[CODE]:

const long long mnx = 8e6 + 9;
const long long mod = 1e9 + 7;
const long long dx[4] = {-1, 0, 0, 1};
const long long dy[4] = {0, -1, 1, 0};
long long n, m;
char s[111][111];
bool u[111][111];
bool check(long long x, long long y) {
    return 0 < x && x < n + 1 && 0 < y && y < m + 1;
}
void dfs(long long x, long long y) {
    if (u[x][y]) { return; }
    u[x][y] = true;
    for (long long i = 0; i < 4; i++) {
        if (check(x + dx[i], y + dy[i]) && s[x + dx[i]][y + dy[i]] == '#') { dfs(x + dx[i], y + dy[i]); }
    }
}
int main() {
    cin >> n >> m;
    for (long long i = 1; i <= n; i++) {
        for (long long j = 1; j <= m; j++) { cin >> s[i][j]; }
    }
    long long qwe = 0;
    for (long long i = 1; i <= n; i++) {
        for (long long j = 1; j <= m; j++) {
            if (s[i][j] == '#') { qwe++; }
        }
    }
    long long res = 11111111111111;
    for (long long i = 1; i <= n; i++) {
        for (long long j = 1; j <= m; j++) {
            if (s[i][j] == '#') {
                long long q = 0;
                for (long long k = 0; k < 4; k++) {
                    if (check(i + dx[k], j + dy[k]) && s[i + dx[k]][j + dy[k]] == '#') q++;
                }
                if (q + 1 < qwe) { res = min(res, q); }
                if (qwe > 1) {
                    s[i][j] = '0';
                    for (long long k = 1; k <= n; k++) {
                        for (long long l = 1; l <= m; l++) { u[k][l] = false; }
                    }
                    long long cnt = 0;
                    for (long long k = 1; k <= n; k++) {
                        for (long long l = 1; l <= m; l++) {
                            if (s[k][l] == '#' && !u[k][l]) {
                                dfs(k, l);
                                cnt++;
                            }
                        }
                    }
                    if (cnt > 1) { res = min(res, 1LL); }
                    s[i][j] = '#';
                }
            }
        }
    }
    if (res == 11111111111111) res -= 11111111111112;
    cout << res << '\n';
    return 0;
}