#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:251700000")
using namespace std;
const long long LINF = 9e18;
const int INF = 2e9;
const int M = 55;
int n, m;
char a[M][M], b[M][M], c[M][M];
vector<pair<int, int> > ans;
map<char, char> dd;
void dfs(int i, int j, char (*a)[55]) {
  if (a[i][j] == 'U') {
    if (a[i][j + 1] != 'U') dfs(i, j + 1, a);
    ans.push_back({i, j});
    a[i][j] = 'L', a[i][j + 1] = 'R';
    a[i + 1][j] = 'L', a[i + 1][j + 1] = 'R';
    return;
  }
  if (a[i + 1][j] == 'U') dfs(i + 1, j, a);
  ans.push_back({i, j});
  a[i][j] = 'U', a[i][j + 1] = 'U';
  a[i + 1][j] = 'D', a[i + 1][j + 1] = 'D';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> a[i][j];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) cin >> b[i][j];
  bool f = 0;
  if (m & 1) {
    dd['D'] = 'L', dd['U'] = 'R', dd['L'] = 'U', dd['R'] = 'D';
    for (int j = 0; j < m; ++j)
      for (int i = 0; i < n; ++i) c[j][i] = dd[a[n - i - 1][j]];
    swap(a, c);
    for (int j = 0; j < m; ++j)
      for (int i = 0; i < n; ++i) c[j][i] = dd[b[n - i - 1][j]];
    swap(b, c);
    swap(n, m);
    f = 1;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (a[i][j] == 'U') dfs(i, j, a);
  vector<pair<int, int> > an = ans;
  ans.clear();
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (b[i][j] == 'U') dfs(i, j, b);
  reverse((ans).begin(), (ans).end());
  for (auto x : ans) an.push_back(x);
  cout << an.size() << '\n';
  for (auto x : an)
    if (!f)
      cout << x.first + 1 << ' ' << x.second + 1 << '\n';
    else
      cout << m - x.second - 1 << ' ' << x.first + 1 << '\n';
}
