/*
  AUTHOR:SOURABH
  CREATED:11:10:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAXN 10000001
#define M 32

using namespace std;
using namespace __gnu_pbds;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,n,m,i,j,k,w,ans;
    pll p;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n>>m;
        vll a(n);
        vector<pll> b(m);
        fn(i,n)
        cin>>a[i];
        fn(i,m)
        cin>>b[i].se>>b[i].fi;
        sort(b.begin(),b.end());
        sort(a.begin(),a.end());
        if(a[n-1]>b[0].fi)
        {cout<<-1;return 0;}
        vll pre(m);
        pre[0]=b[0].se;
        fs(i,1,m)
        pre[i]=max(pre[i-1],b[i].se);
        ans=LLONG_MAX;
        ll dis[n][n];
        do
        {
            fn(i,n)
            {
                fn(j,n)
                dis[i][j]=-1e15;
            }
            fn(i,n-1)
            {
                w=a[i];
                dis[i][i]=0;
                fs(j,i+1,n)
                {
                    w+=a[j];
                    p= {w,-1};
                    k=lower_bound(b.begin(),b.end(),p)-b.begin();
                    k--;
                    if(k>=0)
                        dis[i][j]=pre[k];
                }
            }
            fn(k,n)
            {
                fn(i,n)
                {
                    fn(j,n)
                    dis[i][j]=max(dis[i][j],dis[i][k]+dis[k][j]);
                }
            }
            ans=min(ans,dis[0][n-1]);
        }
        W(next_permutation(a.begin(),a.end()));
        cout<<ans;
    }
    return 0;
}
















#include <bits/stdc++.h>

using namespace std;

// clang-format off
/* accelration */
// 高速バイナリ生成
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
// cin cout の結びつけ解除, stdioと同期しない(入出力非同期化)
// cとstdの入出力を混在させるとバグるので注意
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;

/* alias */
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;

/* define short */
#define pb push_back
#define mp make_pair
#define all(obj) (obj).begin(), (obj).end()
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

/* REP macro */
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) reps(i, 1, n + 1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)

/* debug */
// 標準エラー出力を含む提出はrejectされる場合もあるので注意
#define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" << endl;

/* func */
inline int in_int() {int x; cin >> x; return x;}
inline ll in_ll() {ll x; cin >> x; return x;}
inline string in_str() {string x; cin >> x; return x;}
// search_length: 走査するベクトル長の上限(先頭から何要素目までを検索対象とするか、1始まりで)
template <typename T> inline bool vector_finder(std::vector<T> vec, T element, unsigned int search_length) {
    auto itr = std::find(vec.begin(), vec.end(), element);
    size_t index = std::distance( vec.begin(), itr );
    if (index == vec.size() || index >= search_length) {return false;} else {return true;}
}
template <typename T> inline void print(const vector<T>& v, string s = " ")
    {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template <typename T, typename S> inline void print(const pair<T, S>& p)
    {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << "\n";}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v)
    {for (auto&& p : v) print(p);}
// 第一引数と第二引数を比較し、第一引数(a)をより大きい/小さい値に上書き
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}

int main(){
    rep(I, 1000){
        int si, sj, ti, tj;
        cin >> si >> sj >> ti >> tj;

        int down = si - ti;
        int right = sj - tj;

        string s = "";
        if(down != 0){
            rep(i, abs(down)){
                if(down < 0){
                    s += 'D';
                }
                else
                {
                    s += 'U';
                }
                
            }
        }
        if(right != 0){
            rep(i, abs(right)){
                if(right < 0){
                    s += 'R';
                }
                else
                {
                    s += 'L';
                }
                
            }
        }
        printf("%s\n", s.c_str());
        fflush(stdout);
        ll points;
        cin >> points;
    }
}