[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]:
create constant integer MAXN = 55
let char array mp of size MAXN with array of size MAXN
make bool vis of size MAXN with array of size MAXN
create constant integer array go of size 4 with array of size 2 containing {0, 1, 0, -1, -1, 0, 1, 0}
make ints n, m, and all = 0
declare dfs taking in ints x and y and returning integer
    create int ans = 1
    for i = 0 to 4 exclusive
        create ints xx = x + go [i][0] and yy = y + go[i][1]
        if mp[xx][yy] is equal to '#' and vis[xx][yy] is falsy
            set vis[xx][yy] to true
            set ans to ans + dfs(x + go[i][0], y + go[i][1])
        end of the block
    end of the block
    return ans
end of the block
declare solve
    if all is less than or equal to 2, return -1
    for i = 1 to n
        for j = 1 to m
            if mp[i][j] is equal to '#'
                set mp[i][j] to '.'
                create integer t = 0
                for k = 0 to 4 exclusive
                    make ints xx = i + go[k][0] and yy = j + go[k][1]
                    if mp[xx][yy] is equal to '#'
                        set all contents of vis to 0
                        set vis[xx][yy] to true
                        set t to dfs(xx, yy)
                        break loop
                    end of the block
                end of the block
                set mp[i][j] to '#'
                if t is 0, return -1
                if t is not all - 1, return 1
            end of the block
        end of the block
    end of the block
    return 2
end of the block
define the main function
    read n and m
    set all contents of mp to '.'
    for i = 1 to n
        for j = 1 to m
            read mp[i][j]
            if mp[i][j] is equal to '#', increment all
        end of the block
    end of the block
    print result of solve()
    return to indicate successful execution
end of the block

[CODE]:

const int MAXN = 55;
char mp[MAXN][MAXN];
bool vis[MAXN][MAXN];
const int go[4][2] = {0, 1, 0, -1, -1, 0, 1, 0};
int n, m, all = 0;
int dfs(int x, int y) {
    int ans = 1;
    for (int i = 0; i < 4; i++) {
        int xx = x + go[i][0], yy = y + go[i][1];
        if (mp[xx][yy] == '#' && !vis[xx][yy]) {
            vis[xx][yy] = true;
            ans += dfs(x + go[i][0], y + go[i][1]);
        }
    }
    return ans;
}
int solve() {
    if (all <= 2) return -1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (mp[i][j] == '#') {
                mp[i][j] = '.';
                int t = 0;
                for (int k = 0; k < 4; k++) {
                    int xx = i + go[k][0], yy = j + go[k][1];
                    if (mp[xx][yy] == '#') {
                        memset(vis, 0, sizeof(vis));
                        vis[xx][yy] = true;
                        t = dfs(xx, yy);
                        break;
                    }
                }
                mp[i][j] = '#';
                if (t == 0) return -1;
                if (t != all - 1) { return 1; }
            }
        }
    }
    return 2;
}
int main() {
    cin >> n >> m;
    memset(mp, '.', sizeof(mp));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> mp[i][j];
            if (mp[i][j] == '#') ++all;
        }
    }
    cout << solve() << endl;
    return 0;
}