[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 constant integer MAXN = 55
declare integers n, m, area
declare integer array dx = {-1, 0, 1, 0}
declare integer array dy = {0, 1, 0, -1}
declare integer array bio size MAXN by MAXN
declare character array grid size MAXN by MAXN
declare valid with integers x, y as arguments, returning boolean
    if x is less than 0 or x is greater than or equal to n, return false from function
    if y is less than 0 or y is greater than or equal to m, return false from function
    return true from function
end of the block
declare dfs with integers x, y as arguments, returning void
    let bio[x][y] be 1
    for i = 0 to 4 exclusive
        declare integer xx = x + dx[i]
        declare integer yy = y + dy[i]
        if result of run valid(xx,yy) and grid[xx][yy] is '#' and not bio[xx][yy], run dfs(xx,yy)
    end of the block
end of the block
declare nc with no arguments, returning integer
    for i = 0 to n exclusive
        for j = 0 to m exclusive, let bio[i][j] be 0
    end of the block
    declare integer bk = 0
    for i = 0 to n exclusive
        for j = 0 to m exclusive
            if grid[i][j] is '.', end current loop iteration
            if bio[i][j], end current loop iteration
            run dfs(i,j)
            increment bk
        end of the block
    end of the block
    return bk
end of the block
define the main function
    read n and m
    for i = 0 to n exclusive, read grid[i]
    for i = 0 to n exclusive
        for j = 0 to m exclusive
            if grid[i][j] is '#', increment area
        end of the block
    end of the block
    if area is less than 3
        print "-1\n"
        return to indicate successful execution
    else if area is 3
        print "1\n"
        return to indicate successful execution
    else
        for i = 0 to n exclusive
            for j = 0 to m exclusive
                if grid[i][j] is '.', end current loop iteration
                let gird[i][j] be '.'
                if result of run nc is greater than 1
                    print "1\n"
                    return to indicate successful execution
                end of the block
                let grid[i][j] be '#'
            end of the block
        end of the block
        print "2\n"
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

const int MAXN = 55;
int n, m, area;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int bio[MAXN][MAXN];
char grid[MAXN][MAXN];
bool valid(int x, int y) {
    if (x < 0 || x >= n) return false;
    if (y < 0 || y >= m) return false;
    return true;
}
void dfs(int x, int y) {
    bio[x][y] = 1;
    for (int i = 0; i < 4; i++) {
        int xx = x + dx[i];
        int yy = y + dy[i];
        if (valid(xx, yy) && grid[xx][yy] == '#' && !bio[xx][yy]) { dfs(xx, yy); }
    }
}
int nc() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) { bio[i][j] = 0; }
    }
    int bk = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (grid[i][j] == '.') continue;
            if (bio[i][j]) continue;
            dfs(i, j);
            bk++;
        }
    }
    return bk;
}
int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) { cin >> grid[i]; }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (grid[i][j] == '#') area++;
        }
    }
    if (area < 3) {
        cout << "-1\n";
        return 0;
    } else if (area == 3) {
        cout << "1\n";
        return 0;
    } else {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (grid[i][j] == '.') continue;
                grid[i][j] = '.';
                if (nc() > 1) {
                    cout << "1\n";
                    return 0;
                }
                grid[i][j] = '#';
            }
        }
        cout << "2\n";
    }
    return 0;
}