#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";

template<typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;

const int  MOD=1000000007;
const int N=100005;

void solve(){
	int n, m;
    cin >> n >> m;
    if(n == 1 and m == 0){
        cout << 1 << " " << 3; return;
    }
    if(m < 0 or m >= n-1) {
    	cout << "-1"; return;
    }

    int k = m;
    vector < pair < int, int > > ans(n);

    ans[0].first = 2;
    ans[0].second = 2*n+m-1;
 
    for(int i=1; i<n-1; ++i){
        if(k > 1){
            ans[i].first = ans[i-1].second+1;
            ans[i].second = ans[i].first+1;
        }else if(k == 1){
            ans[i].first = ans[i-1].second+1;
            ans[i].second = ans[i].first+n-m-1;    
        }else{
            ans[i].first = ans[i+k-1].second+k-1;
            ans[i].second = ans[i+k-1].second-k+1;
        }
        --k;
    }
    ans[n-1].first = 1;
    ans[n-1].second = (int)1e9;
    for(auto x: ans) cout << x.first << " " << x.second << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin>>t;                     // DON'T FORGET IT. ^^^  
    for(long int tt=1;tt<=t;tt++){
        solve();
    }
    cerr << "Time : " << 1000 * ((double) clock()) / (double) CLOCKS_PER_SEC << "ms\n";
    return 0;
}
#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PIL = pair<int,ll>;
using PLI = pair<ll,int>;
using PLL = pair<ll,ll>;
using Graph = vector<vector<int>>;
using Cost_Graph = vector<vector<PIL>>;

template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;}
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ROUNDUP(a,b) ((a+b-1)/b)
#define YESNO(T) cout<<(T?"YES":"NO")<<endl
#define yesno(T) cout<<(T?"yes":"no")<<endl
#define YesNo(T) cout<<(T?"Yes":"No")<<endl

const int INFint = 1 << 30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007LL;
const double pi = 3.14159265358979;
const vector<int> h_idx = {-1, 0,0,1};
const vector<int> w_idx = { 0,-1,1,0};

int si,sj;
int now_i,now_j;
vector<vector<int>> tile(50, vector<int>(50));
vector<vector<int>> profit(50, vector<int>(50));
vector<bool> seen(2505,false);
string ans;
string all_ans;
ll best_score;

clock_t start_time;
clock_t now_time;

mt19937 mt((int)time(0));

bool check_time_limit(){
    now_time = clock();
    if ((double)(now_time - start_time) / CLOCKS_PER_SEC > 1.95) return true;
    else return false;
}
// 実行時間が1.95秒を越したらtrue,それまではfalse

void all_resize(){
    return;
}

void all_input(){
    cin >> si >> sj;

    all_resize();

    for (int i = 0; i < 50; i++){
        for (int j = 0; j < 50; j++){
            cin >> tile[i][j];
        }
    }

    for (int i = 0; i < 50; i++){
        for (int j = 0; j < 50; j++){
            cin >> profit[i][j];
        }
    }

    seen[tile[si][sj]] = true;

    return;
}

ll calc_score(string &s){
    int tmp_now_i = si,tmp_now_j = sj;

    ll res = profit[si][sj];

    for (auto x : s){
        if (x == 'U'){
            tmp_now_i += h_idx[0];
            tmp_now_j += w_idx[0];
        }
        else if (x == 'L'){
            tmp_now_i += h_idx[1];
            tmp_now_j += w_idx[1];
        }
        else if (x == 'R'){
            tmp_now_i += h_idx[2];
            tmp_now_j += w_idx[2];
        }
        else{
            tmp_now_i += h_idx[3];
            tmp_now_j += w_idx[3];
        }

        res += profit[tmp_now_i][tmp_now_j];
    }

    return res;
}

void all_output(){

    cout << all_ans << endl;

    return;
}

bool check_range_and_seen(int i,int j){
    if (i < 0 || i >= 50 || j < 0 || j >= 50) return false;

    if (seen[tile[i][j]]) return false;
    else return true;
}

bool random_walk(int &i,int &j){
    if (check_time_limit()) return false;

    vector<int> possible_direction;

    for (int k = 0; k < 4; k++){
        int tmp_next_i = i + h_idx[k];
        int tmp_next_j = j + w_idx[k];

        if (check_range_and_seen(tmp_next_i,tmp_next_j)) possible_direction.push_back(k);
    }

    if (possible_direction.size() == 0) return false;

    int num = mt() % (possible_direction.size());
    int direction = possible_direction[num];

    int next_i = i + h_idx[direction];
    int next_j = j + w_idx[direction];

    if (direction == 0){
        ans.push_back('U');
    }
    else if (direction == 1) ans.push_back('L');
    else if (direction == 2) ans.push_back('R');
    else ans.push_back('D');

    i = next_i;
    j = next_j;
    seen[tile[i][j]] = true;

    return true;
}

void random_walk_all(){
    ans = "";
    now_i = si;
    now_j = sj;

    while (random_walk(now_i,now_j));

    if (chmax(best_score,calc_score(ans))){
        // cout << best_score << endl;
        all_ans = ans;
    }

    return;
}

void solve(){

    ll counter = 0;

    while (!check_time_limit()){
        random_walk_all();
        counter++;

    }

    // cout << counter << endl;

    return;
}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    all_input();

    solve();

    all_output();
}

// 乱択