#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

using pis = pair<int,string>;
const int N = 50;
const int LIMIT = 1e7;
const vector<int> dx{0,1,0,-1}, dy{-1,0,1,0};
const vector<char> D{'U','R','D','L'};

int cnt = 0;
vector<vector<int>> t,p;

bool in_range(const pii &pl) {
    if (pl.first < 0 || pl.first >=N) return false;
    if (pl.second < 0 || pl.second >=N) return false;
    return true;
}

int xy_to_t(const pii &pl) {
    return t[pl.first][pl.second];
}

pis dfs(pii &pos,vector<bool> &tile) {
    pis ret = {0,""};
    cnt++;
    if (cnt > LIMIT) return ret;
    if (!in_range(pos)) return ret;
    if (tile[xy_to_t(pos)]) return ret;
    tile[xy_to_t(pos)] = true;
    pis tmp;
    int best = -1;
    REP(i,D.size()) {
        pos.first += dy[i];
        pos.second += dx[i];
        tmp = dfs(pos,tile);
        pos.first -= dy[i];
        pos.second -= dx[i];
        if (ret.first < tmp.first) {
            best = i;
            swap(ret,tmp);
        }
    }
    tile[xy_to_t(pos)] = false;
    ret.first += p[pos.first][pos.second];
    ret.second.push_back(D[best]);
    return ret;
}


int main(void)
{
    IOS
    pii s;
    cin >> s.first >> s.second;
    REP(i,N) {
        vector<int> t1(N);
        REP(j,N) cin >> t1[j];
        t.push_back(t1);
    }
    REP(i,N) {
        vector<int> p1(N);
        REP(j,N) cin >> p1[j];
        p.push_back(p1);
    }

    vector<bool> tile(N*N);

    pis ans = dfs(s,tile);
    reverse(ALL(ans.second));
    ans.second.pop_back();
    OUT(ans.second)

    return 0;
}


//================code===================//

//#define TLE

#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>
#include <random>
#include <chrono>
//#include <stdint.h>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define ld long double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp pair<int,ld>
#define setl pair<LL,LL>

#define micro 0.000000000001

using namespace std;

LL gcd(LL a, LL b)
{
	if (!(a && b)) return max(a, b);
	return a % b ? gcd(b, a % b) : b;
}

#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl;
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#define LLL LL
#else
#define AT
#define AE
#define ce(t)
#define LLL __int128
#endif

pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{-1,0},{-1,-1}, {0,-1} , {1,-1},{-1,-1} }; //RDLU EWSN

template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl& a, setl& b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl& a, setl& b) { return a.second > b.second; } };

const int max_v = 1e5 + 7;
const int max_k = 5e2 + 7;
const int bsz = (1ll << 10) + 7;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
LL mod =  998244353;//1e9 + 7;
template<typename T, typename U> void MOD(T& a, U b) { a += b; if (a >= mod) a -= mod; };

int main()
{
#ifdef OHSOLUTION
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int a, b; ci(a >> b);

	vector<int> vi(3);
	vi[0] = 0;
	vi[1] = 1;
	vi[2] = 2;

	if (a == b) co(a);
	else
	{
		for (auto& x : vi)
		{
			if (x != a && x != b)
			{
				co(x);
				break;
			}
		}
	}

	return 0;
}
