#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
map<char, char> rev = {{'U', 'L'}, {'D', 'R'}, {'L', 'U'}, {'R', 'D'}};
vector<pair<int, int> > go(vector<vector<int> >& grid, int first, int second,
                           int dir) {
  if (grid[first][second] == dir) return {};
  vector<pair<int, int> > ret;
  if (dir == 'U') {
    ret = go(grid, first + 1, second, 'L');
    ret.push_back({first, second});
  } else {
    ret = go(grid, first, second + 1, 'U');
    ret.push_back({first, second});
  }
  grid[first][second] = grid[first + 1][second] = 'L';
  grid[first][second + 1] = grid[first + 1][second + 1] = 'R';
  return ret;
}
vector<pair<int, int> > solve(vector<vector<int> >& grid) {
  int n = grid.size(), m = grid[0].size();
  vector<pair<int, int> > ret;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j += 2) {
      vector<pair<int, int> > steps = go(grid, i, j, 'L');
      ret.insert(ret.end(), steps.begin(), steps.end());
    }
  }
  return ret;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<int> > from(n, vector<int>(m)), to(n, vector<int>(m));
  for (auto& i : from)
    for (auto& j : i) scanf(" %c", &j);
  for (auto& i : to)
    for (auto& j : i) scanf(" %c", &j);
  if (m % 2 == 1) {
    vector<vector<int> > _from(m, vector<int>(n)), _to(m, vector<int>(n));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) _from[j][i] = from[i][j];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) _to[j][i] = to[i][j];
    from = _from, to = _to;
    for (auto& i : from)
      for (auto& j : i) j = rev[j];
    for (auto& i : to)
      for (auto& j : i) j = rev[j];
  }
  vector<pair<int, int> > solve1 = solve(from);
  vector<pair<int, int> > solve2 = solve(to);
  reverse(solve2.begin(), solve2.end());
  solve1.insert(solve1.end(), solve2.begin(), solve2.end());
  if (m % 2 == 1)
    for (auto& p : solve1) swap(p.first, p.second);
  printf("%d\n", solve1.size());
  for (auto p : solve1) printf("%d %d\n", p.first + 1, p.second + 1);
  return 0;
}
