#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

struct point {
  int h;
  int w;

  point() = default;
  point(int h, int w):
    h(h),
    w(w)
  {};
};

struct node {
  double eval = 0;
  int tile_sum = 0;
  point left_up;
  point right_down;
  point now;
  vector<int> action;
  bitset<2500> visited;

  node() = default;
  node(int e, point n, vector<int> a, bitset<2500> v):
    eval(e),
    now(n),
    action(a),
    visited(v)
  {};

  bool operator<(const node &right) const {
    return eval < right.eval;
  }
  bool operator>(const node &right) const {
    return eval > right.eval;
  }

  bool invalid_walk(point next);
  int bounding_box();
  int edge_dis();
  void make_next(point next, int dir);
  void evaluation();
};

const array<llong, 4> nw = {0, 1, 0, -1};
const array<llong, 4> nh = {-1, 0, 1, 0};
const string ans_char = "URDL";

point start_pos;
vector<vector<int>> tile_id(50, vector<int>(50));
vector<vector<int>> area(50, vector<int>(50));

point get_next_pos(point now, int dir) {
  return point(now.h + nh[dir], now.w + nw[dir]);
}

int node::bounding_box() {
  return (right_down.h - left_up.h) * (right_down.w - left_up.w);
}
bool node::invalid_walk(point next) {
  return next.h < 0 || next.w < 0 || next.h >= 50 || next.w >= 50 ||
      visited[tile_id[next.h][next.w]];
}

void node::make_next(point next, int dir) {
  now = next;
  visited[tile_id[next.h][next.w]] = 1;
  tile_sum += area[next.h][next.w];
  action.push_back(dir);
  left_up.h = min(left_up.h, next.h);
  left_up.w = min(left_up.w, next.w);
  right_down.h = max(right_down.h, next.h);
  right_down.w = max(right_down.w, next.w);
  evaluation();
}

int get_dis(point a, point b) {
  // return abs(b.h - a.h) + abs(b.w - a.w);
  return max(abs(b.h - a.h), abs(b.w - a.w));
}

int node::edge_dis() {
  return min({now.h, now.w, 50 - now.h, 50 - now.w});
}

void node::evaluation() {
  eval += pow(25 - edge_dis(), 2);
  int sum = 0;
  for (int i = 0; i < 4; i++) {
    sum += !invalid_walk(get_next_pos(now, i));
  }
  eval += pow(sum, 2) * 5;
  // eval += bounding_box() * 10;
}

vector<int> beam_search() {
  const double simulate_time = 1700000;
  clock_t s = clock(), f;
  priority_queue<node, vector<node>> que;
  node ret;
 
  node start_node;
  start_node.make_next(start_pos, -1);
  start_node.action.pop_back();
  que.push(start_node);
 
  int max_score = 0;
  while (f = clock(), f - s < simulate_time && que.size()) {
    for (int i = 0; i < 1000 && que.size(); i++) {
      node now_node = que.top();
      que.pop();
 
      bool walked = false;
      for (int j = 0; j < 4; j++) {
        point next_pos = get_next_pos(now_node.now, j);
        if (now_node.invalid_walk(next_pos)) {
          continue;
        }
        walked = true;
        node next_node = now_node;
        next_node.make_next(next_pos, j);
 
        que.push(next_node);
      }
 
      if (!walked && now_node.tile_sum > max_score) {
        max_score = now_node.tile_sum;
        ret = now_node;
      }
    }
  }
 
  cerr << que.size() << endl;
  while (que.size()) {
    node n = que.top();
    que.pop();
    if (n.tile_sum > max_score) {
      max_score = n.tile_sum;
      ret = n;
    }
  }
 
  return ret.action;
}

vector<int> solve() {
  clock_t s = clock();
  return beam_search();
}

int main() {
  cin >> start_pos.h >> start_pos.w;
  for (auto &in: tile_id) {
    for (auto &inin: in) {
      cin >> inin;
    }
  }
  for (auto &in: area) {
    for (auto &inin: in) {
      cin >> inin;
    }
  }

  auto ans = solve();
  for (auto a: ans) {
    cout << ans_char[a];
  }
  cout << endl;

  return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<int>
#define mk make_pair
#define vll vector<long long >
#define loop(i,a,b) for(int i=a;i<=b;i++)
#define loopr(i,a,b) for(int i=b;i>=a;i--)
#define vii vector<vector<int>>
#define ll long long
void io()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
unordered_map < ll, ll > dp;
ll dfs(ll y, ll x) {
	if (x == y)
		return 0;
	if (y == 1)
		return dp[y] = abs(x - y);

	if (dp.find(y) != dp.end())
		return dp[y];
	if (y > x) {
		if (y % 2 == 0) {
			return dp[y] =  min(y - x, 1 + dfs( y / 2, x));
		}
		else

			return dp[y] = min(1 + dfs(y - 1, x), 1 + dfs(y + 1, x));
	}
	else {
		return dp[y] = abs(x - y);
	}

}

int main()
{
	
	ll x, y;
	dp.clear();
	cin >> x >> y;

	cout << dfs(y, x) << endl;
	return 0;
}
