#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <queue>
#define int unsigned long long
using namespace std;
const int maxn=2e5+10;
struct node {
	int id,val;
}a[maxn];
int n;
signed main() {
	int now=0;
	cin>>n>>now;
	for(int i=1;i<=n;i++) {
		cin>>a[i].id>>a[i].val;
	}
	sort(a+1,a+1+n,[](node x,node y)->bool{return x.id<y.id;});
	for(int i=1;i<=n;i++) {
		if(now<a[i].id) {
			cout<<now;
			return 0;
		}
		now+=a[i].val;
	}
	cout<<now;
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll n, k, ans = 0;
void solve(vector<vector<ll> > &v,set<ll> st, ll last, ll val) {
    if(st.size()  == 0) {
        val += v[last][0];
        if(val == k)    {
            ans++;
        }
        return;
    }
    for(auto itr = st.begin(); itr != st.end(); itr++)  {
        set<ll> temp = st;
        temp.erase(*itr);
        solve(v, temp, *itr, val + v[last][*itr]);
    }
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    vector<vector<ll> > v(n, vector<ll> (n, 0));
    for(int i = 0; i < n; i++)  {
        for(int j = 0; j < n; j++ ) {
            cin >> v[i][j];
        }
    }
    set<ll> st;
    for(int i = 1; i < n; i++)  {
        st.insert(i);
    }
    ll val = 0;
    ll last = 0;
    solve(v, st, last, val);
    cout << ans;
}
 
