#include <bits/stdc++.h>

using namespace std;

#define Fast_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define int long long int
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

const int MOD = 998244353;
const int bigMOD = 1e9+7;

/*************** My code start here ****************/

int32_t main()
{
    Fast_IO
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    clock_t danger_close = clock();
    int t = 1;
    // cin >> t;
    while (t--)
    {
        int n, m, X, Y, d = 0, cnt = 0, f = 0;
        cin >> n >> m >> X >> Y;
        vector<string> grid(n);
        vector<pair<int, int>> coins;
        map<pair<int, int>, int> mp;
        for(int i = 0; i < n; i++) {
            cin >> grid[i];
            for(int j = 0; j < m; j++) {
                if(grid[i][j] == 'C')
                    mp[{i, j}] = cnt++;
            }
        }
        queue<tuple<int, int, int>> q;
        q.push({0, 0, 0});
        vector<pair<int, int>> dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
        vector<vector<vector<bool>>> vis(n, vector<vector<bool>>(m, vector<bool>(1 << cnt, false)));
        vis[0][0][0] = true;
        while(!q.empty()) {
            int l = q.size();
            d++;
            while(l--) {
                auto [x, y, mask] = q.front();
                q.pop();
                for(auto [dx, dy]: dirs) {
                    int nx = x+dx, ny = y+dy;
                    if(nx < 0 or nx >= n or ny < 0 or ny >= m or grid[nx][ny] == '#')
                        continue;
                    if(mask == (1<<cnt)-1 and nx == X and ny == Y) {
                        f = 1;
                        break;
                    }
                    int newmask = mask;
                    if(grid[nx][ny] == 'C')
                        newmask = mask | (1<<mp[{nx, ny}]);
                    if(vis[nx][ny][newmask])
                        continue;
                    q.push({nx, ny, newmask});
                    vis[nx][ny][newmask] = true;
                }
            }
            if(f)
                break;
        }
        if(f)
            cout << d << '\n';
        else
            cout << -1 << '\n';
    }
    debug("Total Time: %.3f\n", (double)(clock() - danger_close) / CLOCKS_PER_SEC);
    return 0;
}