[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]:
data=array of 51 by 51 char
visited=array of 51 by 51 bool
dr=array of 4 int filled with 0,0,1,-1
dc=array of 4 int filled with 1,-1,0,0
function Counter (get int i and j, return int)
    if visited[i][j] return 0
    visited[i][j]=true
    ans=0
    if data[i][j] is '#'
        increment ans
        for x=0 to 4 exclusive add Counter(i+dr[x],j+dc[x]) to ans
    end of the block
    return ans
end of the block
define the main function
    n,m=int
    read n,m
    Total=0
    start=pair of int, int
    for i=0 to n exclusive
        for j=o to m exclusive
            read data[i][j]
            if data[i][j] is '#' increment Total, start=i,j
        end of the block
    end of the block
    fill visited with false
    t=Counter(first item of start, second item of start)
    if t < Total
        print 0
        return to indicate successful execution
    else if Total < 3
        print -1
        return to indicate successful execution
    else
        ans=0
        for i=0 to n exclusive
            for j=0 to m exclusive
                if data[i][j] is '#'
                    if i is 6 and j is 5 r=1
                    fill visited with false
                    visited[i][j]=true
                    x,y=int
                    for k=0 to 4 exclusive
                        if data[i+dr[k]][j+dc[k]] is '#'
                            x=i+dr[k]
                            y=j+dc[k]
                            break
                        end of the block
                    end of the block
                    t=Counter(x,y)
                    if t<Total-1
                        print 1
                        return to indicate successful execution
                    end of the block
                end of the block
            end of the block
        end of the block
    end of the block
    print 2
    return to indicate successful execution
end of the block

[CODE]:

char data[51][51];
bool visited[51][51];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
int Counter(int i, int j) {
    if (visited[i][j]) return 0;
    visited[i][j] = true;
    int ans = 0;
    if (data[i][j] == '#') {
        ans++;
        for (int x = 0; x < 4; x++) { ans += Counter(i + dr[x], j + dc[x]); }
    }
    return ans;
}
int main() {
    int n, m;
    cin >> n >> m;
    int Total = 0;
    pair<int, int> start;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> data[i][j];
            if (data[i][j] == '#') Total++, start = pair<int, int>(i, j);
        }
    }
    memset(visited, false, sizeof visited);
    int t = Counter(start.first, start.second);
    if (t < Total) {
        cout << 0 << endl;
        return 0;
    } else if (Total < 3) {
        cout << -1 << endl;
        return 0;
    } else {
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (data[i][j] == '#') {
                    if (i == 6 && j == 5) { int r = 1; }
                    memset(visited, false, sizeof visited);
                    visited[i][j] = true;
                    int x, y;
                    for (int k = 0; k < 4; k++) {
                        if (data[i + dr[k]][j + dc[k]] == '#') {
                            x = i + dr[k];
                            y = j + dc[k];
                            break;
                        }
                    }
                    int t = Counter(x, y);
                    if (t < Total - 1) {
                        cout << "1" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << 2 << endl;
    return 0;
}