[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 character array a size 55 by 55
declare integer array is size 55 by 55
declare integers n, m
declare integer arrays dx size 4 = {-1, 1, 0, 0}, dy size 4 = {0, 0, -1, 1}
declare inline work with integers x, y as arguments, returning void
    if is[x][y] is 1, return from function
    if a[x][y] is not '#', return from function
    let is[x][y] be 1
    declare integer i
    for i = 0 to 4 exclusive, run work with x + dx[i], y + dy[i] as arguments
end of the block
declare inline check with integers x, y as arguments, returning boolean
    let a[x][y] be '.'
    declare integer kk = 0
    set bytes from is to size of is to value 0
    for i = 1 to n inclusive
        for j = 1 to m inclusive
            if a[i][j] is '#' and is[i][j] is 0
                increment kk
                run work(i,j)
            end of the block
    end of the block
    let a[x][y] be '#'
    return kk is greater than 1
end of the block
define the main function
    read n, m
    declare integer kk = 0
    for i = 1 to n inclusive
        for j = 1 to m inclusive
            read a[i][j]
            if a[i][j] is '#', increment kk
        end of the block
    end of the block
    if kk is less than 3
        print -1 and newline
        return to indicate successful execution
    end of the block
    declare integer ans = 2
    for i = 0 to n inclusive
        for j = 1 to m inclusive
            if a[i][j] is '#'
                if result of run check(i,j) is true, let ans be 1
            end of the block
    end of the block
    print ans and newline
    return to indicate successful execution
end of the block

[CODE]:

char a[55][55];
int is[55][55];
int n, m;
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
inline void work(int x, int y) {
    if (is[x][y] == 1) return;
    if (a[x][y] != '#') return;
    is[x][y] = 1;
    int i;
    for (i = 0; i < 4; i++) work(x + dx[i], y + dy[i]);
}
inline bool check(int x, int y) {
    a[x][y] = '.';
    int kk = 0;
    memset(is, 0, sizeof(is));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++)
            if (a[i][j] == '#' && (is[i][j] == 0)) {
                kk++;
                work(i, j);
            }
    }
    a[x][y] = '#';
    return kk > 1;
}
int main() {
    cin >> n >> m;
    int kk = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
            if (a[i][j] == '#') kk++;
        }
    }
    if (kk < 3) {
        cout << -1 << endl;
        return 0;
    }
    int ans = 2;
    for (int i = 0; i <= n; i++) {
        for (int j = 1; j <= m; j++)
            if (a[i][j] == '#') {
                if (check(i, j)) ans = 1;
            }
    }
    cout << ans << endl;
    return 0;
}