#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

struct Ad{ll x, y, r, num;};
struct Recang{
    ll x1, y1, x2, y2;
    ll size(){
        return abs(x2-x1)*abs(y2-y1);
    }
};

const int MAX=9999;
int n;
Ad ads[300];
Recang ans[300];

bool overlap(Recang a, Recang b){
    return max(a.x1,b.x1)<min(a.x2,b.x2)&&max(a.y1,b.y1)<min(a.y2,b.y2);
}

bool check(Recang a, int k){
    REP(i,n){
        if(i==k)
            continue;
        if(overlap(a,ans[i]))
            return 1;
    }
    return 0;
}

void solve(){
    cin >> n;
    int x, y, r;
    REP(i,n){
        cin >> x >> y >> r;
        ads[i]=Ad{x,y,r,i};
    }
    sort(ads,ads+n,[](const Ad& a, const Ad& b){return a.r<b.r;});
    REP(i,n){
        Ad ad=ads[i];
        ans[ad.num]={ad.x,ad.y,ad.x+1,ad.y+1};
    }
    REP(i,n){
        Ad ad=ads[i];
        Recang tmpr={ad.x,ad.y,ad.x+1,ad.y+1};
        while(1){
            bool ok=0;
            tmpr.x1--;
            if(tmpr.x1<0||check(tmpr,ad.num)) tmpr.x1++;
            else ok=1;
            if(tmpr.size()>ad.r) break;
            tmpr.y1--;
            if(tmpr.y1<0||check(tmpr,ad.num)) tmpr.y1++;
            else ok=1;
            if(tmpr.size()>ad.r) break;
            tmpr.x2++;
            if(tmpr.x2>MAX||check(tmpr,ad.num)) tmpr.x2--;
            else ok=1;
            if(tmpr.size()>ad.r) break;
            tmpr.y2++;
            if(tmpr.y2>MAX||check(tmpr,ad.num)) tmpr.y2--;
            else ok=1;
            if(tmpr.size()>ad.r) break;
            if(!ok) break;
        }
        ans[ad.num]=tmpr;
    }
    REP(i,n){
        Recang tmpr=ans[i];
        cout << tmpr.x1 << " ";
        cout << tmpr.y1 << " ";
        cout << tmpr.x2 << " ";
        cout << tmpr.y2 << endl;
    }
}

int main(){
    solve();
    return 0;
}
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 61;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[201][12];

void cmemoInit(){
    rep(i, 201){
        rep(j, 12){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<ll>> pos(2 * 1e6);
    rep(i, 2 * 1e6) pos[i].push_back(-1);
    rep(i, n){
        pos[a[i]].push_back(i);
    }
    rep(i, 2 * 1e6) pos[i].push_back(n);
    ll ans = n;
    rep(i, n){
        rep(j, pos[i].size() - 1){
            if(abs(pos[i][j] - pos[i][j + 1]) > m){
                ans = min(ans, (ll)i);
            }
        }
    }
    cout << ans << endl;

}