#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int si,sj,score[50][50],id[50][50];
    bool ok_id[2500];
    cin >> si >> sj;
    for(int i=0;i<50;i++)
    {
        for(int j=0;j<50;j++)
        {
            cin >> id[i][j];
            ok_id[i*50+j]=true;
        }
    }
    for(int i=0;i<50;i++)
    {
        for(int j=0;j<50;j++)
        {
            cin >> score[i][j];
        }
    }
    bool move_judge[4];
    while(1)
    {
        move_judge[0]=true;//U ↑
        move_judge[1]=true;//D ↓
        move_judge[2]=true;//L ←
        move_judge[3]=true;//R →
        if(si==0)move_judge[0]=false;//上端
        if(si==49)move_judge[1]=false;//下端
        if(sj==0)move_judge[2]=false;//左端
        if(sj==49)move_judge[3]=false;//右端
        int now_id = id[si][sj];
        ok_id[now_id] = false;
        
        if(move_judge[0])
            if(ok_id[id[si-1][sj]]==false)
                move_judge[0] = false;
        if(move_judge[1])
            if(ok_id[id[si+1][sj]]==false)
                move_judge[1] = false;
        if(move_judge[2])
            if(ok_id[id[si][sj-1]]==false)
                move_judge[2] = false;
        if(move_judge[3])
            if(ok_id[id[si][sj+1]]==false)
                move_judge[3] = false;
        
        if(move_judge[0]){
            printf("U");
            si-=1;
            continue;
        }else if(move_judge[1]){
            printf("D");
            si+=1;
            continue;
        }else if(move_judge[2]){
            printf("L");
            sj-=1;
            continue;
        }else if(move_judge[3]){
            printf("R");
            sj+=1;
            continue;
        }else{
            break;
        }
    }
    return 0;
}
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std ;


void ABC203_C(){
    long long int N,K;
    cin >> N >> K;
    
    // 単純に記憶するだけではだめ。
//    vector<int> friendPoint(1000000000000000000,0);
    vector<pair<long long int, long long int>> A(N);
    
    for(int i = 0; i < N; i++){
        cin >> A[i].first >> A[i].second;
    }
    
    sort(A.begin(),A.end());
    for(int i = 0; i < N; i++){
        if(A[i].first > K){
            break;
        }
        K += A[i].second;
    }
    
    cout << K << endl;
}

int main(int argc, const char * argv[]) {
    // insert code here...
    ABC203_C();
    return 0;
}
