#include <bits/stdc++.h>
using namespace std;
int n, m, num;
char s[51][51];
int x[110000], y[110000];
int pos, k;
void change(int x, int y) {
  if (s[x][y] == 'U')
    s[x][y] = 'L', s[x][y + 1] = 'R', s[x + 1][y] = 'L', s[x + 1][y + 1] = 'R';
  else
    s[x][y] = 'U', s[x + 1][y] = 'D', s[x][y + 1] = 'U', s[x + 1][y + 1] = 'D';
}
void work() {
  if (n & 1) {
    while (k) {
      for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
          if (s[i][j] == 'U' && s[i][j + 1] == 'U')
            x[++num] = i, y[num] = j, change(i, j), k -= 2;
      if (k == 0) return;
      for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
          if (s[i][j] == 'L' && s[i + 1][j] == 'L')
            x[++num] = i, y[num] = j, change(i, j), k += 2;
    }
  } else {
    while (k) {
      for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
          if (s[i][j] == 'L' && s[i + 1][j] == 'L')
            x[++num] = i, y[num] = j, change(i, j), k -= 2;
      if (k == 0) return;
      for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
          if (s[i][j] == 'U' && s[i][j + 1] == 'U')
            x[++num] = i, y[num] = j, change(i, j), k += 2;
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    for (int j = 0; j < m; j++)
      if (n & 1)
        k += (s[i][j] == 'U');
      else
        k += (s[i][j] == 'L');
  }
  work();
  pos = num;
  for (int i = 0; i < n; i++) {
    scanf("%s", s[i]);
    for (int j = 0; j < m; j++)
      if (n & 1)
        k += (s[i][j] == 'U');
      else
        k += (s[i][j] == 'L');
  }
  work();
  printf("%d\n", num);
  for (int i = 1; i <= pos; i++) printf("%d %d\n", ++x[i], ++y[i]);
  for (int i = num; i > pos; i--) printf("%d %d\n", ++x[i], ++y[i]);
  return 0;
}
