#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <unordered_map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

typedef unsigned long long ull;

long long MX = 1e18;

int n;
int a[110];
ull x;

ull calc2(long long sum, int k) {
    sum = x - sum;
    if (sum % k) return MX;
    return sum / k;
}

long long f[110][110][110];
ull calc(int k) {
    for (int i = 0; i <= n; ++i)
        for (int h = 0; h <= k; ++h)
            for (int j = 0; j < k; ++j) f[i][h][j] = -MX;
    f[0][1][a[0] % k] = a[0];
    for (int i = 1; i < n; ++i) {
        for (int h = 2; h <= i+1 && h <= k; ++h)
            for (int j = 0; j < k; ++j) {
                f[i][h][j] = max(f[i-1][h][j], f[i-1][h-1][((j-a[i])%k+k)%k] + a[i]);
            }
        f[i][1][a[i]%k] = a[i];
        for (int j = 0; j < k; ++j) {
            f[i][1][j] = max(f[i][1][j], f[i-1][1][j]);
        }
    }
    ull ans = MX;
    for (int j = 0; j < k; ++j) {
        if (f[n-1][k][j] <= 0) continue;
        ans = min(ans, calc2(f[n-1][k][j], k));
    }
    return ans;
}

int main()
{
    cin >> n >> x;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    ull ans = MX;
    for (int k = 1; k <= n; ++k) {
        ull c = calc(k);
        if (c < ans) ans = c;
        
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define V vector
#define debug(v) {for(auto i: v) cout << i << " "; cout << endl;}
#define vcin(v) rep(i, v.size()) cin >> v[i]
#define wcin(v, w) rep(i, v.size()) cin >>v[i] >>w[i]

int main(){
    ll n,k;
    cin >>n >>k;
    ll a,b;
    V<pair<ll,ll>> ab(n);
    rep(i,n){
        cin >>a >>b;
        ab[i]={a,b};
    }

    sort(all(ab));
    ll kane=k,now=0;
    rep(i,n){
        if(kane>=ab[i].first-now){
            kane=kane-ab[i].first+now+ab[i].second;
            now=ab[i].first;
        }
        else break;
    }
    cout <<now+kane;
}