#include<bits/stdc++.h>
#define mp make_pair
#define mulitset
#define nline "\n"
#define ll long long int
#define ss(x) sort(x.begin(),x.end())
#include<map>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define tt(x) ll x;cin>>x;while(x--) 
#define pb push_back
//#define a(x) std::vector<ll> a(x);
#define ins insert
#define sz size
using namespace std;
const int INF = (int)1e+9;
 const int M=1e9+7;

 bool gre(int a,int b){
    if(a>b){
        return true;
    }else{
        return false;
    }
 }
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }

ll fact(int n){
    if(n==1||n==0)return 1;
    else
        return n*fact(n-1);
}
int powm(ll b,ll p,ll m){
    if(p==0){
        return 1;
    }
    ll k=powm(b,p/2,m);
    if(p%2){
        return (mul((k*k),b));
    }else{
        return (mul(k,k));
    }
}


void solve(){
 ll n,k;cin>>n>>k;
 map<ll,ll>mp;
 rep(i,0,n){
  ll a,b;cin>>a>>b;
  mp[a]+=b;
 }
 ll ans=k;
 for(auto it:mp){
  if(ans<it.first){
    cout<<ans<<nline;return;
  }else{
    ans+=it.second;
  }
 }
 cout<<ans;return;


   

}




  







int32_t main(){ //learn "%.nof"printf("%.nof")
    ios_base
    ::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif

solve();

       
}

    

  







    
      
    



#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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 U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, M;
	cin >> N >> M;
	vector<int64> w(N);
	REP(i, N) cin >> w[i];
	int64 wmax = *max_element(all(w));
	vector<PLL> parts(M);
	REP(i, M) {
	  cin >> parts[i].fs >> parts[i].sc;
	  if (parts[i].sc < wmax) {
	    cout << -1 << endl;
	    return 0;
	  }
	}
	vector<int64> cost(1 << N, 0);
	REP(i, 1 << N) {
	  int64 wsum = 0;
	  REP(j, N) {
	    if (i >> j & 1) wsum += w[j];
	  }
	  REP(j, M) {
	    if (parts[j].sc < wsum) chmax(cost[i], parts[j].fs);
	  }
	}
	int64 res = INF_LL;
	vector<int64> ord(N);
	iota(all(ord), 0);
	do {
	  vector<int64> pos(N, 0);
	  FOR(j, 1, N) {
	    int64 bit = 0;
	    for (int64 k = j; k >= 0; k--) {
	      bit |= (1 << ord[k]);
	      chmax(pos[j], pos[k] + cost[bit]);
	    }
	  }
	  chmin(res, pos.back());
	} while (next_permutation(all(ord)));
	cout << res << endl;
}
