#include<bits/stdc++.h>
#define MAXN 50+10
#define MAXM 2500+10

using namespace std;

const int n = 50;

int si,sj;
string Fs = "RDLU";

int Fx[10] = {0,1,0,-1};
int Fy[10] = {1,0,-1,0};

int Soc[MAXM];
bool vis[MAXM];

int t[MAXN][MAXN];
int p[MAXN][MAXN];
string Move,s;

int Now = 0;
int Ans = 0;

const int Time_Limit =  (int) (1.9 * CLOCKS_PER_SEC);

void DFS(int x,int y)
{
	if(Now > Ans)
	{
		Move = s;
		Ans = Now;
	}
	if((int)clock() >  Time_Limit)
	{
		cout << Move;
		exit(0);
	}
	
	vis[t[x][y]] = true;
	Now += Soc[t[x][y]];
	
	for(int i=0;i<4;i++)
	{
		int nx = x + Fx[i];
		int ny = y + Fy[i];
		if(nx < 0 || ny < 0 || nx >= n || ny >= n) continue;
		if(vis[t[nx][ny]]) continue;
		s += Fs[i];
		DFS(nx,ny);
		s.pop_back();
	}
	vis[t[x][y]] = false;
	Now -= Soc[t[x][y]];
}

int main()
{
	scanf("%d%d",&si,&sj);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			scanf("%d",&t[i][j]);
	
	 for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			scanf("%d",&p[i][j]);
			Soc[t[i][j]] += p[i][j];
		}
	
	DFS(si,sj);
	
	cout << Move;
	//cout << Ans;
}
#include<bits/stdc++.h>
using namespace std;
int n,t,a[102],ans;
set<int> q;
void Dfs1(int dep,int sum){
	if(sum>t)
		return;
	if(dep==(n>>1)+1){
		q.insert(sum);
		return;
	}
	Dfs1(dep+1,sum),
	Dfs1(dep+1,sum+a[dep]);
}
void Dfs2(int dep,int sum){
	if(sum>t)
		return;
	if(dep==n+1){
		set<int>::iterator i=q.upper_bound(t-sum);
		--i;
		ans=max(ans,sum+(*i));
		return;
	}
	Dfs2(dep+1,sum),
	Dfs2(dep+1,sum+a[dep]);
}
int main(){
	scanf("%d%d",&n,&t);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	Dfs1(1,0);
	Dfs2((n>>1)+1,0);
	printf("%d\n",ans);
}