#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long int N, K;
  cin >> N >> K;
  int T[N][N];
  
  vector<int> array(0);
  for(int i = 0; i < N; i++){
    array.push_back(i);
  }
  
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cin >> T[i][j];
    }
  }
  
  int ans = 0;
  do{
      long long int tmp = 0;
      for(int i = 0; i < N; i++){
        tmp += T[array[i]][array[(i+1)%N]];
      }
      if(tmp == K) ans++;
  }while(next_permutation(array.begin()+1,array.end()));

  cout << ans << endl;
}
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,k,pr=0;
  cin >> n >> k;
  vector<ll> a(n),b(n);
  vector<P> ab(n);
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    ab[i] = P(a[i],b[i]);
  }
  sort(ab.begin(),ab.end());
  for(int i=0;i<n;i++){
    auto [ta,tb] = ab[i];
    ll dist = ta - pr;
    if (dist>k){
      cout << pr + k << endl;
      return 0;
    }
    k = k - dist + tb;
    pr = ta;
  }
  cout << pr + k << endl;
}
