#include <bits/stdc++.h>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
template<class T> bool chmax(T& a, const T& b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T> bool chmin(T& a, const T& b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

struct Edge {
public:
	int from, to;
	ll C, D;
	Edge() {}
	Edge(int _from, int _to, ll _C, ll _D) {
		from = _from;
		to = _to;
		C = _C;
		D = _D;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef pair<ll, int> P;

ll getTime(ll time, Edge e) {
	return time + e.C + (e.D / (time + 1ll));
}


ll fastestTime(ll time, Edge e) {
	ll mid = sqrt(e.D);
	ll best = mid;
	for (ll i = max(mid - 100, 0ll);i <= mid + 100;i++) {
		if (getTime(best, e) > getTime(i, e)) {
			best = i;
		}
	}
	if (best >= time)return getTime(best, e);
	else return getTime(time, e);
}


vll dijkstra(int s, Graph G) {//s=>始点
	priority_queue<P, vector<P>, greater<P> > que;
	vll D(SZ(G), LINF);
	D[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (D[v] < p.first)continue;
		for (Edge e : G[v]) {
			ll fastest = fastestTime(D[v], e);
			if (D[e.to] > fastest) {
				D[e.to] = fastest;
				que.push(P(D[e.to], e.to));
			}
		}
	}
	return D;
}



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	Graph G(N);
	REP(i, M) {
		int A, B;
		cin >> A >> B;
		ll C, D;
		cin >> C >> D;
		A--;B--;
		G[A].push_back(Edge(A, B, C, D));
		G[B].push_back(Edge(B, A, C, D));
	}
	vll ans = dijkstra(0, G);
	if (ans[N - 1] == LINF) {
		cout << -1 << endl;
	}
	else {
		cout << ans[N - 1] << endl;
	}
	return 0;
}
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const double PI = 3.141592653589793238;
int main() {
  auto start = chrono::system_clock::now();
  ll si, sj;
  cin >> si >> sj;
  ll nowi = si, nowj = sj;
  vector<ll> t(2500);
  for (ll i = 0; i < 50; ++i) {
    for (ll j = 0; j < 50; ++j) {
      cin >> t[50 * i + j];
    }
  }

  vector<ll> p(2500);
  for (ll i = 0; i < 50; ++i) for (ll j = 0; j < 50; ++j) cin >> p[50 * i + j];

  string lastans = "";
  ll lastpnt = 0;
  map<ll, bool> used;
  string ans = "";
  while (true) {
    ll id = 50 * nowi + nowj;
    ll maxi = -1;
    used[t[id]] = true;
    char togo = ' ';
    if (nowj != 0 && !used[t[id - 1]] && maxi < p[id - 1]) {
      togo = 'L';
      maxi = p[id - 1];
    }
    if (nowj != 49 && !used[t[id + 1]] && maxi < p[id + 1]) {
      togo = 'R';
      maxi = p[id + 1];
    }
    if (nowi != 0 && !used[t[id - 50]] && maxi < p[id - 50]) {
      togo = 'U';
      maxi = p[id - 50];
    }
    if (nowi != 49 && !used[t[id + 50]] && maxi < p[id + 50]) {
      togo = 'D';
      maxi = p[id + 50];
    }
    if (togo != ' ')ans += togo;
    switch (togo)
    {
    case 'L': --nowj;
      break;
    case 'R': ++nowj;
      break;
    case 'U': --nowi;
      break;
    case 'D': ++nowi;
      break;
    default:
      goto exit;
    }
  }
exit:;
  nowi = si, nowj = sj;
  lastans = ans;
  ll now = 50 * nowi + nowj;
  lastpnt += p[now];
  for (ll i = 0; i < ans.size(); ++i) {
    switch (ans[i]) {
    case 'L': --nowj;
      break;
    case 'R': ++nowj;
      break;
    case 'U': --nowi;
      break;
    case 'D': ++nowi;
      break;
    }
    lastpnt += p[now];
  }

  string sample = "LRUD";
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> cha(0, 3), rand(1, 1000);
  auto dur = chrono::system_clock::now() - start;

  while (chrono::duration_cast<std::chrono::milliseconds>(dur).count() < 1990) {
    ans = lastans;

    uniform_int_distribution<> change(0, ans.size());
    ll ch = change(mt), at = cha(mt), r = rand(mt);
    if (ch == ans.size()) ans.push_back(sample[at]);
    else ans[ch] = sample[at];

    nowi = si, nowj = sj;
    now = 50 * nowi + nowj;
    map<ll, bool> used;
    used[t[now]] = true;
    ll pnt = p[now];
    for (ll i = 0; i < ans.size(); ++i) {
      switch (ans[i]) {
      case 'L': --nowj;
        break;
      case 'R': ++nowj;
        break;
      case 'U': --nowi;
        break;
      case 'D': ++nowi;
        break;
      }
      if (nowi < 0 || 49 < nowi || nowj < 0 || 49 < nowj) {
        pnt = -1;
        break;
      }
      now = 50 * nowi + nowj;
      if (used[t[now]]) {
        pnt = -1;
        break;
      }
      used[t[now]] = true;
      pnt += p[now];
    }
    if (pnt >= lastpnt) {
      lastpnt = pnt;
      lastans = ans;
    }
    else if (pnt != -1 && r <= 125) {
      lastpnt = pnt;
      lastans = ans;
    }
    dur = chrono::system_clock::now() - start;
  }
  cout << lastans << "\n";
}