#include <bits/stdc++.h>
using namespace std;
const int N = 51;
int n, m;
string a[N], b[N];
vector<pair<int, int> > ans1, ans2;
void fun(int x, int y, int type) {
  if (type == 0) {
    if (a[x][y] == 'L' && a[x + 1][y] == 'U') fun(x + 1, y, 1);
    if (a[x][y] == 'L' && a[x + 1][y] == 'L') {
      ans1.push_back({x + 1, y + 1});
      a[x][y] = a[x][y + 1] = 'U';
      a[x + 1][y] = a[x + 1][y + 1] = 'D';
    }
  } else {
    if (a[x][y + 1] == 'L' && a[x][y] == 'U') fun(x, y + 1, 0);
    if (a[x][y] == 'U' && a[x][y + 1] == 'U') {
      ans1.push_back({x + 1, y + 1});
      a[x][y] = a[x + 1][y] = 'L';
      a[x][y + 1] = a[x + 1][y + 1] = 'R';
    }
  }
}
void fun1(int x, int y, int type) {
  if (type == 0) {
    if (b[x][y] == 'L' && b[x + 1][y] == 'U') fun1(x + 1, y, 1);
    if (b[x][y] == 'L' && b[x + 1][y] == 'L') {
      ans2.push_back({x + 1, y + 1});
      b[x][y] = b[x][y + 1] = 'U';
      b[x + 1][y] = b[x + 1][y + 1] = 'D';
    }
  } else {
    if (b[x][y + 1] == 'L' && b[x][y] == 'U') fun1(x, y + 1, 0);
    if (b[x][y] == 'U' && b[x][y + 1] == 'U') {
      ans2.push_back({x + 1, y + 1});
      b[x][y] = b[x + 1][y] = 'L';
      b[x][y + 1] = b[x + 1][y + 1] = 'R';
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  if (n % 2 == 0) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (a[i][j] == 'L') fun(i, j, 0);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (b[i][j] == 'L') fun1(i, j, 0);
  } else {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (a[i][j] == 'U') fun(i, j, 1);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++)
        if (b[i][j] == 'U') fun1(i, j, 1);
  }
  cout << ans1.size() + ans2.size() << endl;
  reverse(ans2.begin(), ans2.end());
  for (auto i : ans1) cout << i.first << " " << i.second << endl;
  for (auto i : ans2) cout << i.first << " " << i.second << endl;
}
