#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<pair<int, int>> b(10, make_pair(-1, -1));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char c = a[i][j];
if (c >= '0' && c <= '9') {
int num = c - '0';
b[num] = make_pair(i, j);
}
}
}
string ops;
cin >> ops;
int x = 0, y = 0;
bool ok = false;
for (char c : ops) {
if (ok) break;
int nx = x, ny = y;
if (c == 'L') ny--;
else if (c == 'R') ny++;
else if (c == 'U') nx--;
else if (c == 'D') nx++;
if (nx < 0 || nx >= n || ny < 0 || ny >= m) {
continue;
}
if (a[nx][ny] == '#') {
x = nx; y = ny;
ok = true;
break;
} else if (a[nx][ny] == '.') {
x = nx; y = ny;
} else {
x = nx; y = ny;
int p = a[x][y] - '0';
int q = p + 1;
if (q > 9) {
continue;
}
if (b[q].first == -1) {
continue;
}
x = b[q].first;
y = b[q].second;
}
}
cout << x + 1 << " " << y + 1 << endl;
return 0;
}