#include <bits/stdc++.h>
using namespace std;
string arr[55], arr2[55];
vector<pair<int, int> > hasil;
int i, j, n, t, tc, r, x, y, k, c;
void tuker_lr(int x, int y) {
  arr[x][y] = 'U';
  arr[x + 1][y] = 'D';
  arr[x][y + 1] = 'U';
  arr[x + 1][y + 1] = 'D';
}
void tuker_ud(int x, int y) {
  arr[x][y] = 'L';
  arr[x][y + 1] = 'R';
  arr[x + 1][y] = 'L';
  arr[x + 1][y + 1] = 'R';
}
void l_u_ganjil(int x, int y) {
  if (arr[x + 1][y] == 'L') {
    tuker_lr(x, y);
    hasil.push_back(make_pair(x, y));
  } else if (arr[x + 1][y + 1] == 'U') {
    tuker_ud(x + 1, y);
    hasil.push_back(make_pair(x + 1, y));
    tuker_lr(x, y);
    hasil.push_back(make_pair(x, y));
  } else {
    l_u_ganjil(x + 1, y + 1);
    tuker_ud(x + 1, y);
    hasil.push_back(make_pair(x + 1, y));
    tuker_lr(x, y);
    hasil.push_back(make_pair(x, y));
  }
}
void u_d_ganjil(int x, int y) {
  if (arr[x][y + 1] == 'U') {
    tuker_ud(x, y);
    hasil.push_back(make_pair(x, y));
  } else if (arr[x][y + 1] == 'L') {
    l_u_ganjil(x, y + 1);
    tuker_ud(x, y);
    hasil.push_back(make_pair(x, y));
  } else {
    u_d_ganjil(x - 1, y + 1);
    l_u_ganjil(x, y + 1);
    tuker_ud(x, y);
    hasil.push_back(make_pair(x, y));
  }
}
int main() {
  scanf("%d %d", &r, &c);
  for (i = 0; i < r; i++) cin >> arr[i];
  for (i = 0; i < r; i++) cin >> arr2[i];
  if (c % 2 == 1) {
    for (j = 0; j < c; j++)
      for (i = 0; i < r; i++)
        if (arr[i][j] == 'L') l_u_ganjil(i, j);
  } else {
    for (j = 0; j < c; j++)
      for (i = 0; i < r; i++)
        if (arr[i][j] == 'U') u_d_ganjil(i, j);
  }
  for (j = 0; j < c; j++) {
    for (i = 0; i < r; i++) {
      if (arr[i][j] == arr2[i][j])
        continue;
      else if (arr[i][j] == 'U')
        u_d_ganjil(i, j);
      else
        l_u_ganjil(i, j);
    }
  }
  printf("%d\n", hasil.size());
  for (i = 0; i < hasil.size(); i++)
    printf("%d %d\n", hasil[i].first + 1, hasil[i].second + 1);
}
