Language: C++

int H, W;
int save_min = -1;
void dfs(int x, int y, int touch)
{
        if (a[y][x] == 1) {
                touch++;
                if (save_min != -1 && touch >= save_min) return;
        }
        else if (a[y][x] == -1) return;
        if (y == H -1 && x == W - 1) {
                result.push_back(touch);
                if (save_min > touch) save_min = touch;
                if (touch == 0) {
                        cout << 0 << endl;
                        exit(0);
                }
                return;
        }
        for (int i = 0; i < 2; ++i) {
                if (i == 0) { // right
                        if (a[y][x+1] == -1) continue;
                        if (a[y][x+1] == 1 && a[y+1][x] == 0) continue;
                        dfs(x+1, y, touch);
                }
                else { // down
                        if (a[y+1][x] == -1) continue;
                        dfs(x, y+1, touch);
                }
        }
}
int main()
{
        cin >> H >> W;
        for (int i = 0; i < 100; ++i) {
                for (int j = 0; j < 100; ++j) {
                        a[i][j] = -1;
                }
        }
        for (int i = 0; i < H; ++i) {
                std::string s;
                cin >> s;
                for (int j = 0; j < W; ++j) {
                        a[i][j] = s[j] == '.' ? 0 : 1;
                }
        }
        dfs(0, 0, 0);
        int cnt = result.size();
        int min = -1;
        for (int i = 0; i < cnt; ++i) {
                if (min == -1) {
                        min = result[i];
                }
                else if (min > result[i]) {
                        min = result[i];
                }
        }
        cout << min << endl;
}


Compiler output:
a.cc: In function 'void dfs(int, int, int)':
a.cc:5:13: error: 'a' was not declared in this scope
    5 |         if (a[y][x] == 1) {
      |             ^
a.cc:11:17: error: 'result' was not declared in this scope
   11 |                 result.push_back(touch);
      |                 ^~~~~~
a.cc:14:25: error: 'cout' was not declared in this scope
   14 |                         cout << 0 << endl;
      |                         ^~~~
a.cc:14:38: error: 'endl' was not declared in this scope
   14 |                         cout << 0 << endl;
      |                                      ^~~~
a.cc:15:25: error: 'exit' was not declared in this scope
   15 |                         exit(0);
      |                         ^~~~
a.cc:1:1: note: 'exit' is defined in header '<cstdlib>'; this is probably fixable by adding '#include <cstdlib>'
  +++ |+#include <cstdlib>
    1 | int H, W;
a.cc:21:29: error: 'a' was not declared in this scope
   21 |                         if (a[y][x+1] == -1) continue;
      |                             ^
a.cc:22:29: error: 'a' was not declared in this scope
   22 |                         if (a[y][x+1] == 1 && a[y+1][x] == 0) continue;
      |                             ^
a.cc:26:29: error: 'a' was not declared in this scope
   26 |                         if (a[y+1][x] == -1) continue;
      |                             ^
a.cc: In function 'int main()':
a.cc:33:9: error: 'cin' was not declared in this scope
   33 |         cin >> H >> W;
      |         ^~~
a.cc:36:25: error: 'a' was not declared in this scope
   36 |                         a[i][j] = -1;
      |                         ^
a.cc:40:22: error: 'string' is not a member of 'std'
   40 |                 std::string s;
      |                      ^~~~~~
a.cc:1:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
  +++ |+#include <string>
    1 | int H, W;
a.cc:41:24: error: 's' was not declared in this scope
   41 |                 cin >> s;
      |                        ^
a.cc:43:25: error: 'a' was not declared in this scope
   43 |                         a[i][j] = s[j] == '.' ? 0 : 1;
      |                         ^
a.cc:47:19: error: 'result' was not declared in this scope
   47 |         int cnt = result.size();
      |                   ^~~~~~
a.cc:57:9: error: 'cout' was not declared in this scope
   57 |         cout << min << endl;
      |         ^~~~
a.cc:57:24: error: 'endl' was not declared in this scope
   57 |         cout << min << endl;
      |                        ^~~~