[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]:
declare integer array tab size 55 by 55
declare integer array vis size 55 by 55
declare integers n, m
declare czysc with no arguments, returning void
    for i = 1 to n inclusive
        for j = 1 to m inclusive, let vis[i][j] be 0
    end of the block
    return from function
end of the block
declare dfs with integers i, j as arguments, returning void
    let vis[i][j] be 1
    if tab[i+1][j] is 1 and vis[i+1][j] is 0, run dfs(i+1 and j)
    if tab[i-1][j] is 1 and vis[i-1][j] is 0, run dfs(i-1, j)
    if tab[i][j+1] is 1 and vis[i][j+1] is 0, run dfs with i, j + 1 as arguments
    if tab[i][j-1] is 1 and vis[i][j-1] is 0, run dfs(i,j-1)
    return from function
end of the block
define the main function
    declare character c
    read n, m
    declare integers licz = 0
    for i = 1 to n inclusive
        for j = 1 to m inclusive
            read c
            if c is '#'
                let tab[i][j] be 1
                increment licz
            end of the block
        end of the block
    end of the block
    if licz is less than 3
        print "-1" and newline
        return to indicate successful execution
    end of the block
    declare integers wynik = 5
    declare integer akt
    declare integer odw
    for i = 1 to n inclusive
        for j = 1 to m inclusive
            if tab[i][j] is 1
                let akt be 0
                let akt be tab[i + 1][j] + tab[i - 1][j] + tab[i][j + 1] + tab[i][j - 1]
                if akt is 1
                    print "1" and newline
                    return to indicate successful execution
                else
                    run czysc
                    let tab[i][j] be 0
                    if tab[i+1][j] is 1
                        run dfs with i + 1, j as arguments
                    else
                        if tab[i-1][j] is 1
                            run dfs(i-1,j)
                        else
                            run dfs(i,j+1)
                        end of the block
                    end of the block
                    let tab[i][j] be 1
                end of the block
                let odw be vis[i + 1][j] + vis[i - 1][j] + vis[i][j + 1] + vis[i][j - 1]
                if odw is less than akt
                    print "1" and newline
                    return to indicate successful execution
                end of the block
            end of the block
        end of the block
    end of the block
    print "2" and newline
    return to indicate successful execution
end of the block

[CODE]:

int tab[55][55];
int vis[55][55];
int n, m;
void czysc() {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) { vis[i][j] = 0; }
    }
    return;
}
void dfs(int i, int j) {
    vis[i][j] = 1;
    if (tab[i + 1][j] == 1 && vis[i + 1][j] == 0) { dfs(i + 1, j); }
    if (tab[i - 1][j] == 1 && vis[i - 1][j] == 0) { dfs(i - 1, j); }
    if (tab[i][j + 1] == 1 && vis[i][j + 1] == 0) { dfs(i, j + 1); }
    if (tab[i][j - 1] == 1 && vis[i][j - 1] == 0) { dfs(i, j - 1); }
    return;
}
int main() {
    char c;
    cin >> n >> m;
    int licz = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> c;
            if (c == '#') {
                tab[i][j] = 1;
                licz++;
            }
        }
    }
    if (licz < 3) {
        cout << "-1" << endl;
        return 0;
    }
    int wynik = 5;
    int akt;
    int odw;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (tab[i][j] == 1) {
                akt = 0;
                akt = tab[i + 1][j] + tab[i - 1][j] + tab[i][j + 1] + tab[i][j - 1];
                if (akt == 1) {
                    cout << "1" << endl;
                    return 0;
                } else {
                    czysc();
                    tab[i][j] = 0;
                    if (tab[i + 1][j] == 1) {
                        dfs(i + 1, j);
                    } else {
                        if (tab[i - 1][j] == 1) {
                            dfs(i - 1, j);
                        } else {
                            dfs(i, j + 1);
                        }
                    }
                    tab[i][j] = 1;
                }
                odw = vis[i + 1][j] + vis[i - 1][j] + vis[i][j + 1] + vis[i][j - 1];
                if (odw < akt) {
                    cout << "1" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "2" << endl;
    return 0;
}