[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 integer array A of size 100 X 100
create integer array B of size 26000
create vector integer array NEB of size 27000
let yy be integer with yy=0
create integer arrays vis,low,malow,tim,F of sizes 27000 each
create integer t=1
create integer uu=0
create integer vector check
in the function dfs which takes a integer s
    set low[s] = t
    set vis[s] = 1
    set tim[s] =t
    add 1 to t
    create integer pp=0
    for i=0 to NEB[s].size exclusive
        create integer l = NEB[s][i]
        if F[s] is not equal to 1
            if vis[l] is equal to 1
                set low[s] to minimum of low[s] and tim[l]
            else do the following
                add 1 to pp
                set F[l] =s
                call dfs with argument l
                create integer u=s
                set low[u] = minimum of low[u] and low[l]
                set malow[w] to maximum of malow[u] and low[l]
            end of the block
        end of the block
    end of the block
    create integer u = s
    is s=yy and pp>1
        set uu=1
        add s to the end of check
    else if ss is not equal to yy and malow[u] >= tim[u]
        set uu to 1
        add s to end of check
    end of the block
end of the block
define the main function
    n,m = integers
    read n and m
    create integer no=0
    for i=1 to n inclusive
        for j=1 to m inclusive
            c= char
            read c
            if c is equal to #
                increment no
                set A[i][j] to 1
                set B[(m + 1) * i + j] = 1
                set yy = (m + 1) * i + j
            end of the block
        end of the block
    end of the block
    create integer array of size 4 P = {-1, 1, (0 - m - 1), m + 1}{-1, 1, (0 - m - 1), m + 1}
    for i=1 to 2700 exclusive
        for j=0 to 4 exclusive
            if i + P[j] >= 0 and B[i + P[j]] = 1 then add i+P[j] to the end of NEB[i]
        end of the block
    end of the block
    call dfs on yy
    if no<3
        then print -1
    else do the following
        if uu is 1
            print 1 and new line
        else do the following
            print 2
    end of the block
end of the block

[CODE]:

int A[100][100];
int B[26000];
vector<int> NEB[27000];
int yy = 0;
int vis[27000], low[27000], malow[27000], tim[27000], F[27000];
int t = 1;
int uu = 0;
vector<int> check;
void dfs(int s) {
    low[s] = t;
    vis[s] = 1;
    tim[s] = t;
    t++;
    int pp = 0;
    for (int i = 0; i < NEB[s].size(); i++) {
        int l = NEB[s][i];
        if (F[s] != l) {
            if (vis[l] == 1) {
                low[s] = min(low[s], tim[l]);
            } else {
                pp++;
                F[l] = s;
                dfs(l);
                int u = s;
                low[u] = min(low[u], low[l]);
                malow[u] = max(malow[u], low[l]);
            }
        }
    }
    int u = s;
    if (s == yy && pp > 1) {
        uu = 1;
        check.push_back(s);
    } else if (s != yy && malow[u] >= tim[u]) {
        uu = 1;
        check.push_back(s);
    }
}
int main() {
    int n, m;
    cin >> n >> m;
    int no = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            char c;
            cin >> c;
            if (c == '#') {
                no++;
                A[i][j] = 1;
                B[(m + 1) * i + j] = 1;
                yy = (m + 1) * i + j;
            }
        }
    }
    int P[4] = {-1, 1, (0 - m - 1), m + 1};
    for (int i = 1; i < 2700; i++) {
        for (int j = 0; j < 4; j++) {
            if (i + P[j] >= 0 && B[i + P[j]] == 1) NEB[i].push_back(i + P[j]);
        }
    }
    dfs(yy);
    if (no < 3)
        cout << -1 << endl;
    else {
        if (uu == 1)
            cout << 1 << endl;
        else
            cout << 2 << endl;
    }
}