#include<bits/stdc++.h>

#define endl "\n"
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int N = 2e5 + 5;

int n, cur = 0;
vector<pii> gr[N];
vector<int> ans;

void Solve() {
  cin >> n;
  ans.assign(n, -1);
  for (int i = 1, a, b; i < n; i++) {
    cin >> a >> b;
    gr[a].emplace_back(b, i);
    gr[b].emplace_back(a, i);
  }
  queue<int> q;
  for (int i = 1; i <= n; i++)
    if (gr[i].size() == 1)
      q.push(i);
  while(q.size()) {
    int v = q.front();
    q.pop();
    for (auto [v, id]: gr[v]) {
      if (ans[id] == -1) {
        q.emplace(v);
        ans[id] = cur++;
      }
    }
  }
  for (int i = 1; i < n; i++)
    cout << ans[i] << " ";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  //auto start = chrono::high_resolution_clock::now();
    Solve();
  //auto end = chrono::high_resolution_clock::now();
  //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  return 0;
}


#include<bits/stdc++.h>

#define endl "\n"
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int N = 1e5 + 5;

int n;

void Solve() {
  cin >> n;
  for (int i = 0; i < n - 1; i++)
    cout << i << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  //auto start = chrono::high_resolution_clock::now();
    Solve();
  //auto end = chrono::high_resolution_clock::now();
  //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  return 0;
}


#include<bits/stdc++.h>

#define endl "\n"
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int N = 1e5 + 5;

int n;

void Solve() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cout << i << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  //auto start = chrono::high_resolution_clock::now();
    Solve();
  //auto end = chrono::high_resolution_clock::now();
  //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  return 0;
}


#include<bits/stdc++.h>

#define endl "\n"
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int N = 1e5 + 5;

int n, cur = 0;
vector<pii> gr[N];
vector<int> ans;

void Solve() {
  cin >> n;
  ans.assign(n, -1);
  for (int i = 1, a, b; i < n; i++) {
    cin >> a >> b;
    gr[a].emplace_back(b, i);
    gr[b].emplace_back(a, i);
  }
  queue<int> q;
  for (int i = 1; i <= n; i++)
    if (gr[i].size() == 1)
      q.push(i);
  while(q.size()) {
    int v = q.front();
    q.pop();
    for (auto [u, id]: gr[v]) {
      if (ans[id] == -1) {
        q.push(u);
        ans[id] = cur++;
        assert(cur <= n);
      }
    }
  }
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  //auto start = chrono::high_resolution_clock::now();
    Solve();
  //auto end = chrono::high_resolution_clock::now();
  //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  return 0;
}


#include<bits/stdc++.h>

#define endl "\n"
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int N = 1e5 + 5;

int n, cur = 0;
vector<pii> gr[N];
vector<int> ans;
bool used[N];

void Solve() {
  cin >> n;
  ans.assign(n, -1);
  for (int i = 1, a, b; i < n; i++) {
    cin >> a >> b;
    gr[a].emplace_back(b, i);
    gr[b].emplace_back(a, i);
  }
  queue<int> q;
  for (int i = 1; i <= n; i++)
    if (gr[i].size() == 1)
      q.push(i);
  while(q.size()) {
    int v = q.front();
    q.pop();
    for (auto [u, id]: gr[v]) {
      if (!used[u]) {
        q.push(u);
        ans[id] = cur++;
        used[u] = 1;
      }
    }
  }
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  //auto start = chrono::high_resolution_clock::now();
    Solve();
  //auto end = chrono::high_resolution_clock::now();
  //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  return 0;
}


#include<bits/stdc++.h>

#define endl "\n"
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int N = 1e5 + 5;

int n, cur = 0;
vector<pii> gr[N];
vector<int> ans;
bool used[N];

void Solve() {
  cin >> n;
  ans.assign(n, -1);
  for (int i = 1, a, b; i < n; i++) {
    cin >> a >> b;
    gr[a].emplace_back(b, i);
    gr[b].emplace_back(a, i);
  }
  queue<int> q;
  for (int i = 1; i <= n; i++)
    if (gr[i].size() == 1)
      q.push(i);
  while(q.size()) {
    int v = q.front();
    used[v] = 1;
    q.pop();
    for (auto [u, id]: gr[v]) {
      if (!used[u]) {
        q.push(u);
        ans[id] = cur++;
        used[u] = 1;
      }
    }
  }
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  //auto start = chrono::high_resolution_clock::now();
    Solve();
  //auto end = chrono::high_resolution_clock::now();
  //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  return 0;
}


#include<bits/stdc++.h>

#define endl "\n"
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int N = 2e5 + 5;

int n, cur = 0;
vector<pii> gr[N];
vector<int> ans;

void Solve() {
  cin >> n;
  ans.assign(n, -1);
  for (int i = 1, a, b; i < n; i++) {
    cin >> a >> b;
    gr[a].emplace_back(b, i);
    gr[b].emplace_back(a, i);
  }
  queue<int> q;
  for (int i = 1; i <= n; i++)
    if (gr[i].size() == 1)
      q.push(i);
  while(q.size()) {
    int v = q.front();
    q.pop();
    for (auto [v, id]: gr[v]) {
      if (ans[id] == -1) {
        q.emplace(v);
        ans[id] = cur++;
      }
    }
  }
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  //auto start = chrono::high_resolution_clock::now();
    Solve();
  //auto end = chrono::high_resolution_clock::now();
  //cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

ll ar[500009],vis[500009],br[500009],cr[500009],cnt;
map<ll,ll>mp1;
vector<ll>v[500009];
map<pair<ll,ll>,ll>mp;
//void dfs(ll j)
//{
//    vis[j]=1;
//    for(ll i=0; i<v[j].size(); i++)
//    {
//        ll x=v[j][i];
//
//        if(vis[x]==0)
//        {
//            mp[{j,x}]=cnt;
//            mp[{x,j}]=cnt;
//            cnt++;
//            dfs(x);
//        }
//    }
//}

int main()
{
    ll a,b,c,i,j,k,x,y,z,f,g,h;
    string s,d;
    cin>>a;
    for(i=1; i<a; i++)
    {
        cin>>ar[i]>>br[i];
//        mp1[ar[i]]++;
//        mp1[br[i]]++;
        x=ar[i];
        y=br[i];
        v[x].push_back(y);
        v[y].push_back(x);
    }
    z=0;
    k=0;
    for(i=1; i<=a; i++)
    {
        if(v[i].size()>z)
        {
            vis[i]=k;
            z=vis[i];
            k++;
            cr[i]=1;
        }
    }

    for(i=1;i<a;i++)
    {
        if(cr[i]==0)
        {
            vis[i]=k;
            k++;
        }
    }
    for(i=1; i<a; i++)
    {
        cout<<vis[i]<<endl;
    }
}

//7
//3 2
//5 7
//4 2
//7 6
//6 3
//1 6


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

ll ar[500009],vis[500009],br[500009],cnt;
map<ll,ll>mp1;
vector<ll>v[500009];
map<pair<ll,ll>,ll>mp;
void dfs(ll j)
{
    vis[j]=1;
    //cout<<j<<endl;
    for(ll i=0; i<v[j].size(); i++)
    {
        ll x=v[j][i];
        if(vis[x]==0)
        {
            mp[ {j,x}]=cnt;
            mp[ {x,j}]=cnt;
            cnt++;
            dfs(x);
        }
    }
}
int main()
{
    ll a,b,c,i,j,k,x,y,z,f,g,h;
    string s,d;
    cin>>a;
    for(i=1; i<a; i++)
    {
        cin>>ar[i]>>br[i];
        mp1[ar[i]]++;
        mp1[br[i]]++;
        x=ar[i];
        y=br[i];
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(i=1; i<=a; i++)
    {
        if(vis[i]==0 && mp1[i]>0)
        {
            dfs(i);
        }
    }
    for(i=1; i<a; i++)
    {
        cout<<mp[ {ar[i],br[i]}]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

ll ar[500009],vis[500009],br[500009],cr[500009],cnt;
map<ll,ll>mp1;
vector<ll>v[500009];
map<pair<ll,ll>,ll>mp;
//void dfs(ll j)
//{
//    vis[j]=1;
//    for(ll i=0; i<v[j].size(); i++)
//    {
//        ll x=v[j][i];
//
//        if(vis[x]==0)
//        {
//            mp[{j,x}]=cnt;
//            mp[{x,j}]=cnt;
//            cnt++;
//            dfs(x);
//        }
//    }
//}

int main()
{
    ll a,b,c,i,j,k,x,y,z,f,g,h;
    string s,d;
    cin>>a;
    for(i=1; i<a; i++)
    {
        cin>>ar[i]>>br[i];
//        mp1[ar[i]]++;
//        mp1[br[i]]++;
        x=ar[i];
        y=br[i];
        v[x].push_back(i);
        v[y].push_back(i);
    }
    //z=0;
    k=0;
    for(i=1; i<=a; i++)
    {
        if(v[i].size()>=3)
        {
            for( j : v[i])
            {
                if(cr[j]==0)
                {
                    vis[j]=k;
                    k++;
                    cr[j]=1;
                }
            }
        }
    }

    for(i=1;i<a;i++)
    {
        if(cr[i]==0)
        {
            vis[i]=k;
            k++;
        }
    }
    for(i=1; i<a; i++)
    {
        cout<<vis[i]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

ll ar[500009],vis[500009],br[500009],cnt;
map<ll,ll>mp1;
vector<ll>v[500009];
map<pair<ll,ll>,ll>mp;
void dfs(ll j)
{
    vis[j]=1;
    //cout<<j<<endl;
    for(ll i=0; i<v[j].size(); i++)
    {
        ll x=v[j][i];
        if(vis[x]==0)
        {
            mp[ {j,x}]=cnt;
            mp[ {x,j}]=cnt;
            cnt++;
            dfs(x);
        }
    }
}
int main()
{
    ll a,b,c,i,j,k,x,y,z,f,g,h;
    string s,d;
    cin>>a;
    for(i=1; i<a; i++)
    {
        cin>>ar[i]>>br[i];
        mp1[ar[i]]++;
        mp1[br[i]]++;
        x=ar[i];
        y=br[i];
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(i=1; i<=a; i++)
    {
        if(vis[i]==0 && mp[i]>0)
        {
            dfs(i);
        }
    }
    for(i=1; i<a; i++)
    {
        cout<<mp[ {ar[i],br[i]}]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

ll ar[500009],vis[500009],br[500009],cnt;
//map<ll,ll>mp,mp1;
vector<ll>v[500009];
map<pair<ll,ll>,ll>mp;
void dfs(ll j)
{
    vis[j]=1;
    //cout<<j<<endl;
    for(ll i=0; i<v[j].size(); i++)
    {
        ll x=v[j][i];
        if(vis[x]==0)
        {
            mp[ {j,x}]=cnt;
            mp[ {x,j}]=cnt;
            cnt++;
            dfs(x);
        }
    }
}
int main()
{
    ll a,b,c,i,j,k,x,y,z,f,g,h;
    string s,d;
    //dfs();
    cin>>a;
    for(i=1; i<a; i++)
    {
        cin>>ar[i]>>br[i];
        x=ar[i];
        y=br[i];
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(i=1; i<=a; i++)
    {
        if(vis[i]==0)
        {
            dfs(i);
        }
    }
    for(i=1; i<a; i++)
    {
        cout<<mp[ {ar[i],br[i]}]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

ll ar[500009],vis[500009],br[500009],cr[500009],cnt;
map<ll,ll>mp1;
vector<ll>v[500009];
map<pair<ll,ll>,ll>mp;
void dfs(ll j)
{
    vis[j]=1;
    for(ll i=0; i<v[j].size(); i++)
    {
        ll x=v[j][i];

        if(vis[x]==0)
        {
            mp[{j,x}]=cnt;
            mp[{x,j}]=cnt;
            cnt++;
            dfs(x);
        }
    }
}

int main()
{
    ll a,b,c,i,j,k,x,y,z,f,g,h;
    string s,d;
    cin>>a;
    for(i=1; i<a; i++)
    {
        cin>>ar[i]>>br[i];
//        mp1[ar[i]]++;
//        mp1[br[i]]++;
        x=ar[i];
        y=br[i];
        v[x].push_back(y);
        v[y].push_back(x);
    }
    z=0;
    for(i=1; i<=a; i++)
    {
        if(v[i].size()>z)
        {
            vis[i]=z;
            z++;
            cr[i]=1;
        }
    }

    for(i=1;i<=a;i++)
    {
        if(cr[i]==0)
        {
            vis[i]=z;
            z++;
        }
    }
    for(i=1; i<a; i++)
    {
        cout<<vis[i]<<endl;
    }
}

//7
//3 2
//5 7
//4 2
//7 6
//6 3
//1 6


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

ll ar[500009],vis[500009],br[500009],cr[500009],cnt;
map<ll,ll>mp1;
vector<ll>v[500009];
map<pair<ll,ll>,ll>mp;
//void dfs(ll j)
//{
//    vis[j]=1;
//    for(ll i=0; i<v[j].size(); i++)
//    {
//        ll x=v[j][i];
//
//        if(vis[x]==0)
//        {
//            mp[{j,x}]=cnt;
//            mp[{x,j}]=cnt;
//            cnt++;
//            dfs(x);
//        }
//    }
//}

int main()
{
    ll a,b,c,i,j,k,x,y,z,f,g,h;
    string s,d;
    cin>>a;
    for(i=1; i<a; i++)
    {
        cin>>ar[i]>>br[i];
//        mp1[ar[i]]++;
//        mp1[br[i]]++;
        x=ar[i];
        y=br[i];
        v[x].push_back(y);
        v[y].push_back(x);
    }
    z=0;
    for(i=1; i<=a; i++)
    {
        if(v[i].size()>z)
        {
            vis[i]=z;
            z++;
            cr[i]=1;
        }
    }

    for(i=1;i<a;i++)
    {
        if(cr[i]==0)
        {
            vis[i]=z;
            z++;
        }
    }
    for(i=1; i<a; i++)
    {
        cout<<vis[i]<<endl;
    }
}

//7
//3 2
//5 7
//4 2
//7 6
//6 3
//1 6


#include<bits/stdc++.h>
using namespace std;

#define ll long long int

#define Bit_off(val,pos)       (val & (~(1<<pos)))
#define Bit_on(val,pos)        (val | (1<<pos))
#define Bit_toggle(val,pos)    (val ^ (1<<pos))
#define Bit_check(val,pos)     (bool)(val & (1<<pos))
#define odd_even(val)          (bool)(val & 1)
#define koita_1_ase(val)       (__builtin_popcount(val))

ll ar[500009],vis[500009],br[500009],cr[500009],cnt;
map<ll,ll>mp1;
vector<ll>v[500009];
//map<pair<ll,ll>,ll>mp;

int main()
{
    ll a,b,c,i,j,k,x,y,z,f,g,h;
    string s,d;
    cin>>a;
    for(i=1; i<a; i++)
    {
        cin>>ar[i]>>br[i];
//        mp1[ar[i]]++;
//        mp1[br[i]]++;
        x=ar[i];
        y=br[i];
        v[x].push_back(i);
        v[y].push_back(i);
    }
    //z=0;
    k=0;
    for(i=1; i<=a; i++)
    {
        if(v[i].size()>=3)
        {
            for( int j : v[i])
            {
                if(cr[j]==0)
                {
                    vis[j]=k;
                    k++;
                    cr[j]=1;
                }
            }
        }
    }

    for(i=1;i<a;i++)
    {
        if(cr[i]==0)
        {
            vis[i]=k;
            k++;
        }
    }
    for(i=1; i<a; i++)
    {
        cout<<vis[i]<<endl;
    }
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

vector<vector<pair<int,int> > > to;

int n;

int main(){
	cin >> n;
	to.resize(n + 1);

	for (int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		to[u].push_back(mp(v, i));
		to[v].push_back(mp(u, i));
	}

	vector<int> ans(n - 1, -1);

	int m = 2;

	for (int i = 1; i <= n; i++){
		if (to[i].size() == 1){
			ans[to[i][0].ss] = m--;
		}
	}

	for (int i = 0; i < n - 1; i++){
		if (ans[i] == -1){
			if (m == 0) m=3;
			ans[i] = m++;
			if (m == 1) m=3;
		}

		cout << ans[i] << '\n';
	}
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

vector<vector<pair<int,int> > > to;

vector<int> subsz;
vector<pair<long long, int> > ans;

int n;

void pp(int u, int pre){
	subsz[u] += 1;

	for (auto &vx : to[u]){
		int v = vx.ff;
		if (v != pre){
			pp(v, u);
			subsz[u] += subsz[v];
		}
	}
}

void solve(int u, int pre, int path){
	if (path != -1){
		ans.pb(mp((subsz[u] - subsz[pre]) * 1LL * subsz[pre], path));
	}
	for (auto &vx : to[u]){
		int v = vx.ff;
		if (v != pre){
			int tmpu = subsz[u];
			int tmpv = subsz[v];

			subsz[u] = subsz[u] - subsz[v];
			subsz[v] = tmpu;

			solve(v, u, vx.ss);

			subsz[u] = tmpu;
			subsz[v] = tmpv;
		}
	}
}

int main(){
	cin >> n;
	to.resize(n + 1);

	for (int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		to[u].push_back(mp(v, i));
		to[v].push_back(mp(u, i));
	}

	subsz.resize(n + 1);

	pp(1, 1);
	solve(1, 1, -1);

	sort(ans.begin(), ans.end());

	vector<int> realans(n - 1);

	int y = n - 2;

	for (auto &a : ans){
		realans[a.ss] = y;
		y--;
	}

	// reverse(realans.begin(), realans.end() );
	for (int i = 0; i < n - 1; i++) cout << realans[i] << '\n';
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

vector<vector<pair<int,int> > > to;

int n;

int main(){
	cin >> n;
	to.resize(n + 1);

	for (int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		to[u].push_back(mp(v, i));
		to[v].push_back(mp(u, i));
	}

	vector<int> ans(n - 1, -1);

	int m = 0;

	for (int i = 1; i <= n; i++){
		if (to[i].size() == 1){
			if (ans[to[i][0].ss] == -1) ans[to[i][0].ss] = m++;

			if (m == 3) break;
		}
	}

	for (int i = 0; i < n - 1; i++){
		if (ans[i] == -1){
			ans[i] = m++;
		}

		cout << ans[i] << '\n';
	}
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

vector<vector<pair<int,int> > > to;

int n;

int main(){
	cin >> n;
	to.resize(n + 1);

	for (int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		to[u].push_back(mp(v, i));
		to[v].push_back(mp(u, i));
	}

	vector<int> ans(n - 1, -1);

	int m = 0;

	for (int i = 1; i <= n; i++){
		if (to[i].size() == 1){
			ans[to[i][0].ss] = m++;
			// cout << 'x' << m << '\n';
		}
	}

	for (int i = 0; i < n - 1; i++){
		if (ans[i] == -1) ans[i] = m++;

		cout << ans[i] << '\n';
	}
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

vector<vector<pair<int,int> > > to;

int n;

int main(){
	cin >> n;
	to.resize(n + 1);

	for (int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		to[u].push_back(mp(v, i));
		to[v].push_back(mp(u, i));
	}

	vector<int> ans(n - 1, -1);

	int m = 0;
	if (n == 3){
		cout << 1 << ' ' << 2 << '\n';
		return 0;
	}

	for (int i = 1; i <= n; i++){
		if (to[i].size() == 1){
			ans[to[i][0].ss] = m++;
		}
	}

	for (int i = 0; i < n - 1; i++){
		if (ans[i] == -1){
			ans[i] = m++;
		}

		cout << ans[i] << '\n';
	}
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

vector<vector<pair<int,int> > > to;

vector<int> subsz;
vector<pair<long long, int> > ans;

int n;

void pp(int u, int pre){
	subsz[u] += 1;

	for (auto &vx : to[u]){
		int v = vx.ff;
		if (v != pre){
			pp(v, u);
			subsz[u] += subsz[v];
		}
	}
}

void solve(int u, int pre, int path){
	if (path != -1){
		ans.pb(mp((subsz[u] - subsz[pre]) * 1LL * subsz[pre], path));
	}
	for (auto &vx : to[u]){
		int v = vx.ff;
		if (v != pre){
			int tmpu = subsz[u];
			int tmpv = subsz[v];

			subsz[u] = subsz[u] - subsz[v];
			subsz[v] = tmpu;

			solve(v, u, vx.ss);

			subsz[u] = tmpu;
			subsz[v] = tmpv;
		}
	}
}

int main(){
	cin >> n;
	to.resize(n + 1);

	for (int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		to[u].push_back(mp(v, i));
		to[v].push_back(mp(u, i));
	}

	subsz.resize(n + 1);

	pp(1, 1);
	solve(1, 1, -1);

	sort(ans.begin(), ans.end());

	vector<int> realans(n - 1);

	int y = n - 2;

	for (auto &a : ans){
		realans[a.ss] = y;
		y--;
	}

	reverse(realans.begin(), realans.end() );
	for (int i = 0; i < n - 1; i++) cout << realans[i] << '\n';
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

vector<vector<pair<int,int> > > to;

int n;

int main(){
	cin >> n;
	to.resize(n + 1);

	for (int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		to[u].push_back(mp(v, i));
		to[v].push_back(mp(u, i));
	}

	vector<int> ans(n - 1, -1);

	int m = 0;

	for (int i = 1; i <= n; i++){
		if (to[i].size() == 1){
			ans[to[i][0].ss] = m++;

			if (m == 3) break;
		}
	}

	for (int i = 0; i < n - 1; i++){
		if (ans[i] == -1){
			ans[i] = m++;
		}

		cout << ans[i] << '\n';
	}
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

vector<vector<pair<int,int> > > to;

int n;

int main(){
	cin >> n;
	to.resize(n + 1);

	for (int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		to[u].push_back(mp(v, i));
		to[v].push_back(mp(u, i));
	}

	vector<int> ans(n - 1, -1);

	int m = 0;

	for (int i = 1; i < n; i++){
		if (to[i].size() == 1){
			ans[to[i][0].ss] = m++;
		}
	}

	for (int i = 0; i < n - 1; i++){
		if (ans[i] == -1) ans[i] = m++;

		cout << ans[i] << '\n';
	}

}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

vector<vector<pair<int,int> > > to;

int n;

int main(){
	cin >> n;
	to.resize(n + 1);

	for (int i = 0; i < n - 1; i++){
		int u, v;
		cin >> u >> v;
		to[u].push_back(mp(v, i));
		to[v].push_back(mp(u, i));
	}

	vector<int> ans(n - 1, -1);

	int m = 2;

	for (int i = 1; i <= n; i++){
		if (to[i].size() == 1){
			ans[to[i][0].ss] = m--;
		}
	}

	for (int i = 0; i < n - 1; i++){
		if (ans[i] == -1){
			ans[i] = m++;
			if (m == 1) m=3;
		}

		cout << ans[i] << '\n';
	}
}


#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#define int long long

using namespace std;

vector<vector<pair<int, int>>> gr;
int l = 0, r;
vector<int> ans;
void dfs(int p, int v, bool fl) {
	for (pair<int, int> u : gr[v]) {
		if (u.first == p)
			continue;
		if (fl)
			ans[u.second] = l++;
		else
			ans[u.second] = r--;
		dfs(v, u.first, !fl);
	}
}

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	int n;
	cin >> n;
	r = n - 2;
	gr.resize(n);
	ans.resize(n - 1);
	for (int i = 0; i < n - 1; ++i) {
		int v, u;
		cin >> v >> u;
		gr[--v].push_back({ --u, i });
		gr[u].push_back({ v, i });
	}
	dfs(-1, 0, 0);
	for (int i = 0; i < n - 1; ++i)
		cout << ans[i] << '\n';
	return 0;
}


#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#define int long long

using namespace std;

vector<vector<pair<int, int>>> gr;
int l = 0, r;
vector<int> ans;
void dfs(int p, int v, bool fl) {
	for (pair<int, int> u : gr[v]) {
		if (u.first == p)
			continue;
		if (fl)
			ans[u.second] = l++;
		else
			ans[u.second] = r--;
		dfs(v, u.first, fl = !fl);
	}
}

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	int n;
	cin >> n;
	r = n - 2;
	gr.resize(n);
	ans.resize(n - 1);
	for (int i = 0; i < n - 1; ++i) {
		int v, u;
		cin >> v >> u;
		gr[--v].push_back({ --u, i });
		gr[u].push_back({ v, i });
	}
	dfs(-1, 0, 0);
	for (int i = 0; i < n - 1; ++i)
		cout << ans[i] << '\n';
	return 0;
}


#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#define int long long

using namespace std;

vector<vector<pair<int, int>>> gr;
int l = 0, r;
vector<int> ans;
bool dfs(int p, int v, bool fl) {
	bool ch = 0;
	for (pair<int, int> u : gr[v]) {
		if (u.first == p)
			continue;
		ch = 1;
		if (fl)
			ans[u.second] = l++;
		else
			ans[u.second] = r--;
		fl = dfs(v, u.first, !fl);
	}
	return ch ? fl : !fl;
}

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	int n;
	cin >> n;
	r = n - 2;
	gr.resize(n);
	ans.resize(n - 1);
	for (int i = 0; i < n - 1; ++i) {
		int v, u;
		cin >> v >> u;
		gr[--v].push_back({ --u, i });
		gr[u].push_back({ v, i });
	}
	dfs(-1, 0, 0);
	for (int i = 0; i < n - 1; ++i)
		cout << ans[i] << '\n';
	return 0;
}


using System;
using System.Linq;

namespace Megacity
{
    public class City
    {
        public int X { get; set; }
        public int Y { get; set; }
        public int Population { get; set; }
        public double DistanceToOrigin { get; set; }
    }

    partial class Megacity
    {
        static void Main(string[] args)
        {
            int n, s, start = 0;
            double radiusNeeded = 0.0;
            City[] cities;

            n = NextInt();
            s = NextInt();
            cities = new City[n];

            for (int i = 0; i < n; i++)
            {
                cities[i] = new City
                {
                    X = NextInt(),
                    Y = NextInt(),
                    Population = NextInt()
                };

                cities[i].DistanceToOrigin = Math.Sqrt((cities[i].Y * cities[i].Y) + (cities[i].X * cities[i].X));
            }

            cities = cities.OrderBy(c => c.DistanceToOrigin).ToArray();

            while (s < 1000000 && start < n)
            {
                s += cities[start].Population;
                radiusNeeded = cities[start].DistanceToOrigin;
                start++;
            }

            if (s >= 1000000)
                Console.WriteLine(radiusNeeded.ToString().Replace(',', '.'));
            else
                Console.WriteLine(-1);
        }
    }

    partial class Megacity
    {
        static string[] tokens = new string[0];
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int NextInt()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return tokens[cur_token++];
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        var sc = new Scanner();
        var n = sc.Integer();
        var m = sc.Integer();

        var l = new KeyValuePair<double, int>[n];
        for (int i = 0; i < n; i++)
        {
            var x = sc.Integer();
            var y = sc.Integer();
            var v = sc.Integer();
            var r = Math.Sqrt(x * x + y * y);
            l[i] = new KeyValuePair<double, int>(r, v);
        }
        var a = l.OrderBy(x => x.Key).ToArray();
        if (m == 1000000)
        {
            Console.WriteLine(0.0);
            return;
        }
        for (int i = 0; i < n; i++)
        {
            m += a[i].Value;
            if (m >= 1000000)
            {
                Console.WriteLine(a[i].Key.ToString("F7"));
                return;
            }
        }
        Console.WriteLine(-1);
        return;

    }
}

public class Scanner
{
    readonly TextReader reader;
    string[] buffer = new string[0];
    int position;

    public char[] Separator { get; set; }
    public Scanner(TextReader reader = null, string separator = null)
    {
        if (reader == null)
            this.reader = Console.In;
        else
            this.reader = reader;
        if (string.IsNullOrEmpty(separator))
            separator = " ";
        this.Separator = separator.ToCharArray();

    }
    public string Scan()
    {
        if (this.position < this.buffer.Length)
            return this.buffer[this.position++];
        this.buffer = this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        this.position = 0;
        return this.buffer[this.position++];
    }

    public string[] ScanToLineEnd()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        var size = this.buffer.Length - this.position;
        var ar = new string[size];
        Array.Copy(this.buffer, position, ar, 0, size);
        return ar;

    }

    public string ScanLine()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine();
        else
        {
            var sb = new StringBuilder();
            for (; this.position < buffer.Length; this.position++)
            {
                sb.Append(this.buffer[this.position]);
                sb.Append(' ');
            }
            return sb.ToString();
        }
    }

    public int Integer()
    {
        return int.Parse(this.Scan());
    }
    public long Long()
    {
        return long.Parse(this.Scan());
    }
    public double Double()
    {
        return double.Parse(this.Scan());
    }

    public int[] IntArray(int length)
    {
        var a = new int[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Integer();
        return a.ToArray();
    }
    public long[] LongArray(int length)
    {
        var a = new long[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Long();
        return a.ToArray();
    }
    public double[] DoubleArray(int length)
    {
        var a = new double[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Double();
        return a.ToArray();
    }

}
//*/


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        var sc = new Scanner();
        var n = sc.Integer();
        var m = sc.Integer();

        var l = new KeyValuePair<int, int>[n];
        for (int i = 0; i < n; i++)
        {
            var x = sc.Integer();
            var y = sc.Integer();
            var v = sc.Integer();
            var r = (x * x) + (y * y);
            l[i] = new KeyValuePair<int, int>(r, v);
        }
        var a = l.OrderBy(x => x.Key).ToArray();
        for (int i = 0; i < n; i++)
        {
            m += a[i].Value;
            if (m >= 1000000)
            {
                var r = Math.Sqrt(a[i].Key);
                Console.WriteLine(r.ToString("F7"));
                return;
            }
        }
        Console.WriteLine(-1);
        return;

    }
}

public class Scanner
{
    readonly TextReader reader;
    string[] buffer = new string[0];
    int position;

    public char[] Separator { get; set; }
    public Scanner(TextReader reader = null, string separator = null)
    {
        if (reader == null)
            this.reader = Console.In;
        else
            this.reader = reader;
        if (string.IsNullOrEmpty(separator))
            separator = " ";
        this.Separator = separator.ToCharArray();

    }
    public string Scan()
    {
        if (this.position < this.buffer.Length)
            return this.buffer[this.position++];
        this.buffer = this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        this.position = 0;
        return this.buffer[this.position++];
    }

    public string[] ScanToLineEnd()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        var size = this.buffer.Length - this.position;
        var ar = new string[size];
        Array.Copy(this.buffer, position, ar, 0, size);
        return ar;

    }

    public string ScanLine()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine();
        else
        {
            var sb = new StringBuilder();
            for (; this.position < buffer.Length; this.position++)
            {
                sb.Append(this.buffer[this.position]);
                sb.Append(' ');
            }
            return sb.ToString();
        }
    }

    public int Integer()
    {
        return int.Parse(this.Scan());
    }
    public long Long()
    {
        return long.Parse(this.Scan());
    }
    public double Double()
    {
        return double.Parse(this.Scan());
    }

    public int[] IntArray(int length)
    {
        var a = new int[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Integer();
        return a.ToArray();
    }
    public long[] LongArray(int length)
    {
        var a = new long[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Long();
        return a.ToArray();
    }
    public double[] DoubleArray(int length)
    {
        var a = new double[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Double();
        return a.ToArray();
    }

}
//*/


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        var sc = new Scanner();
        var n = sc.Integer();
        var m = sc.Integer();
        if (m == 1000000)
        {
            Console.WriteLine(0.0);
            return;
        }
        var l = new KeyValuePair<double, int>[n];
        for (int i = 0; i < n; i++)
        {
            var x = sc.Integer();
            var y = sc.Integer();
            var v = sc.Integer();
            var r = Math.Sqrt(x * x + y * y);
            l[i] = new KeyValuePair<double, int>(r, v);
        }
        var a = l.OrderBy(x => x.Key).ToArray();
        for (int i = 0; i < n; i++)
        {
            m += a[i].Value;
            if (m >= 1000000)
            {
                Console.WriteLine(a[i].Key);
                return;
            }
        }
        Console.WriteLine(-1);
        return;

    }
}

public class Scanner
{
    readonly TextReader reader;
    string[] buffer = new string[0];
    int position;

    public char[] Separator { get; set; }
    public Scanner(TextReader reader = null, string separator = null)
    {
        if (reader == null)
            this.reader = Console.In;
        else
            this.reader = reader;
        if (string.IsNullOrEmpty(separator))
            separator = " ";
        this.Separator = separator.ToCharArray();

    }
    public string Scan()
    {
        if (this.position < this.buffer.Length)
            return this.buffer[this.position++];
        this.buffer = this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        this.position = 0;
        return this.buffer[this.position++];
    }

    public string[] ScanToLineEnd()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        var size = this.buffer.Length - this.position;
        var ar = new string[size];
        Array.Copy(this.buffer, position, ar, 0, size);
        return ar;

    }

    public string ScanLine()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine();
        else
        {
            var sb = new StringBuilder();
            for (; this.position < buffer.Length; this.position++)
            {
                sb.Append(this.buffer[this.position]);
                sb.Append(' ');
            }
            return sb.ToString();
        }
    }

    public int Integer()
    {
        return int.Parse(this.Scan());
    }
    public long Long()
    {
        return long.Parse(this.Scan());
    }
    public double Double()
    {
        return double.Parse(this.Scan());
    }

    public int[] IntArray(int length)
    {
        var a = new int[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Integer();
        return a.ToArray();
    }
    public long[] LongArray(int length)
    {
        var a = new long[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Long();
        return a.ToArray();
    }
    public double[] DoubleArray(int length)
    {
        var a = new double[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Double();
        return a.ToArray();
    }

}
//*/


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
        var sc = new Scanner();
        var n = sc.Integer();
        var m = sc.Integer();

        var l = new KeyValuePair<int, int>[n];
        for (int i = 0; i < n; i++)
        {
            var x = sc.Integer();
            var y = sc.Integer();
            var v = sc.Integer();
            var r = (x * x) + (y * y);
            l[i] = new KeyValuePair<int, int>(r, v);
        }
        var a = l.OrderBy(x => x.Key).ToArray();
        for (int i = 0; i < n; i++)
        {
            m += a[i].Value;
            if (m >= 1000000)
            {
                var r = Math.Sqrt(a[i].Key);
                Console.WriteLine(r.ToString(ci));
                return;
            }
        }
        Console.WriteLine(-1);
        return;

    }
}

public class Scanner
{
    readonly TextReader reader;
    string[] buffer = new string[0];
    int position;

    public char[] Separator { get; set; }
    public Scanner(TextReader reader = null, string separator = null)
    {
        if (reader == null)
            this.reader = Console.In;
        else
            this.reader = reader;
        if (string.IsNullOrEmpty(separator))
            separator = " ";
        this.Separator = separator.ToCharArray();

    }
    public string Scan()
    {
        if (this.position < this.buffer.Length)
            return this.buffer[this.position++];
        this.buffer = this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        this.position = 0;
        return this.buffer[this.position++];
    }

    public string[] ScanToLineEnd()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine().Split(this.Separator, StringSplitOptions.RemoveEmptyEntries);
        var size = this.buffer.Length - this.position;
        var ar = new string[size];
        Array.Copy(this.buffer, position, ar, 0, size);
        return ar;

    }

    public string ScanLine()
    {
        if (this.position >= this.buffer.Length)
            return this.reader.ReadLine();
        else
        {
            var sb = new StringBuilder();
            for (; this.position < buffer.Length; this.position++)
            {
                sb.Append(this.buffer[this.position]);
                sb.Append(' ');
            }
            return sb.ToString();
        }
    }

    public int Integer()
    {
        return int.Parse(this.Scan());
    }
    public long Long()
    {
        return long.Parse(this.Scan());
    }
    public double Double()
    {
        return double.Parse(this.Scan());
    }

    public int[] IntArray(int length)
    {
        var a = new int[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Integer();
        return a.ToArray();
    }
    public long[] LongArray(int length)
    {
        var a = new long[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Long();
        return a.ToArray();
    }
    public double[] DoubleArray(int length)
    {
        var a = new double[length];
        for (int i = 0; i < length; i++)
            a[i] = this.Double();
        return a.ToArray();
    }

}
//*/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeForce_242_B
{
    class Program
    {
        struct Sity
        {
            public long x;
            public long y;
            public long Members;
            public double Range;
        }
        static void Main(string[] args)
        {
            List<Sity> Neightboard = new List<Sity>();

            string str = Console.ReadLine();
            string[] strArray = str.Split(' ');
            int count = int.Parse(strArray[0]);
            long mebers = long.Parse(strArray[1]);
            for(int i=0 ;i< count; i++)
            {
                string sityString = Console.ReadLine();
                string[] strMass = sityString.Split(' ');
                Sity newSity = new Sity();
                newSity.x = long.Parse(strMass[0]);
                newSity.y = long.Parse(strMass[1]);
                newSity.Members= long.Parse(strMass[2]);
                newSity.Range= getLength(newSity.x, newSity.y);
                Neightboard.Add(newSity);
            }

            Neightboard = Neightboard.OrderBy(m => m.Range).ToList();

            double result=0;

            int index = 0;
            while(mebers<1000000 && index< count)
            {
                result = Neightboard[index].Range;
                mebers = mebers + Neightboard[index].Members;
                index++;
            }
            if (mebers < 1000000)
                result = -1;
            result = Math.Round(result, 7);
            string ResultStr =result.ToString();
            Console.WriteLine(ResultStr.Replace(',','.'));

            Console.ReadLine();

        }

        public static double getLength(long x, long y)
        {
            double result = Math.Pow(Math.Pow(x, 2) + Math.Pow(y, 2), 0.5);
            return result;

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeForce_242_B
{
    class Program
    {
        struct Sity
        {
            public long x;
            public long y;
            public long Members;
            public double Range;
        }
        static void Main(string[] args)
        {
            List<Sity> Neightboard = new List<Sity>();

            string str = Console.ReadLine();
            string[] strArray = str.Split(' ');
            int count = int.Parse(strArray[0]);
            long mebers = long.Parse(strArray[1]);
            for(int i=0 ;i< count; i++)
            {
                string sityString = Console.ReadLine();
                string[] strMass = sityString.Split(' ');
                Sity newSity = new Sity();
                newSity.x = long.Parse(strMass[0]);
                newSity.y = long.Parse(strMass[1]);
                newSity.Members= long.Parse(strMass[2]);
                newSity.Range= getLength(newSity.x, newSity.y);
                Neightboard.Add(newSity);
            }

            Neightboard = Neightboard.OrderBy(m => m.Range).ToList();

            double result=0;

            int index = 0;
            while(mebers<1000000 && index< count)
            {
                result = Neightboard[index].Range;
                mebers = mebers + Neightboard[index].Members;
                index++;
            }
            if (mebers < 1000000)
                result = -1;
            result = Math.Round(result, 7);
            Console.WriteLine(result);

            Console.ReadLine();

        }

        public static double getLength(long x, long y)
        {
            double result = Math.Pow(Math.Pow(x, 2) + Math.Pow(y, 2), 0.5);
            return result;

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int  population = int.Parse(s[1]);
           // ArrayList R = new ArrayList();
            int[] rank = new int[200000000];
            int x = 0, y = 0;

            for (long i = 1; i <= n; i++) {
                string[] ss = Console.ReadLine().Split(' ');
                x = int.Parse(ss[0]); y = int.Parse(ss[1]);
                //if() R.Add(x * x + y * y);
                rank[(x * x) + (y * y)] += int.Parse(ss[2]);
            }

            //R.Sort();
            int pos = 0;
            if (population < 1000000)
            {
                for (int i = 0; i < 200000000; i++)
                {
                    population += rank[i];
                    if (population >= 1000000) { pos = i; break; }
                }
            }

            if (population >= 1000000) { Console.WriteLine( Math.Sqrt(pos).ToString().Replace(',','.')); }
            else { Console.WriteLine("-1"); }

           //Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            long  population = long.Parse(s[1]);
            ArrayList R = new ArrayList();
            int[] rank = new int[15000];
            int x = 0, y = 0;

            for (int i = 1; i <= n; i++) {
                s = Console.ReadLine().Split(' ');
                x = int.Parse(s[0]); y = int.Parse(s[1]);
                R.Add(x * x + y * y);
                rank[x * x + y * y] += int.Parse(s[2]);
            }

            R.Sort();
            int pos = 0;
            for (int i = 0; i < n; i++) {
                population += rank[(int)R[i]];
                if (population >= 1000000) { pos = i; break; }
            }

            if (population >= 1000000) { Console.WriteLine( Math.Sqrt((int)R[pos]).ToString("#.0000000").Replace('.',',')); }
            else { Console.WriteLine("-1"); }

           //Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            long  population = long.Parse(s[1]);
            ArrayList R = new ArrayList();
            int[] rank = new int[15000];
            int x = 0, y = 0;

            for (int i = 1; i <= n; i++) {
                s = Console.ReadLine().Split(' ');
                x = int.Parse(s[0]); y = int.Parse(s[1]);
                R.Add(x * x + y * y);
                rank[x * x + y * y] += int.Parse(s[2]);
            }

            R.Sort();
            int pos = 0;
            for (int i = 0; i < n; i++) {
                population += rank[(int)R[i]];
                if (population >= 1000000) { pos = i; break; }
            }

            if (population >= 1000000) { Console.WriteLine( Math.Sqrt((int)R[pos]).ToString("#.0000000").Replace(',','.')); }
            else { Console.WriteLine("-1"); }

           //Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long  population = long.Parse(s[1]);
           // ArrayList R = new ArrayList();
            long[] rank = new long[15000];
            long x = 0, y = 0;

            for (long i = 1; i <= n; i++) {
                s = Console.ReadLine().Split(' ');
                x = int.Parse(s[0]); y = int.Parse(s[1]);
                //if() R.Add(x * x + y * y);
                rank[x * x + y * y] += int.Parse(s[2]);
            }

            //R.Sort();
            double pos = 0;
            for (long i = 0; i < 15000; i++) {
                population += rank[i];
                if (population >= 1000000) { pos = i; break; }
            }

            if (population >= 1000000) { Console.WriteLine( Math.Sqrt(pos).ToString().Replace(',','.')); }
            else { Console.WriteLine("-1"); }

          // Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {

            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int  population = int.Parse(s[1]);
            ArrayList radius = new ArrayList();
            ArrayList rank = new ArrayList();

            int x = 0, y = 0,r=0,indx=0;
            int max = 0;
            /*for (long i = 0; i < n; i++)
            {
                list[i] = Console.ReadLine();
                string[] ss = list[i].Split(' ');
                x = int.Parse(ss[0]); y = int.Parse(ss[1]);
                max = (max < x * x + y * y) ? x * x + y * y : max;

            }*/

            //int[] rank = new int[max+1];

            for (long i = 0; i < n; i++) {
                string[] ss = Console.ReadLine().Split(' ');
                x = int.Parse(ss[0]); y = int.Parse(ss[1]);
                r = x*x +y*y ;
                max = (max < r) ? r : max;
                indx = radius.IndexOf(r);
                if (indx >= 0) { rank[indx] = (int)rank[indx] + int.Parse(ss[2]); }
                else { radius.Add(r); rank.Add(int.Parse(ss[2])) ; }

            }

            int pos = 0;
            if (population < 1000000)
            {
                for (int i = 0; i <= max; i++)
                {
                    indx = radius.IndexOf(i);
                    if (indx < 0) { continue; }
                    population += (int)rank[indx];
                    if (population >= 1000000) { pos = i; break; }
                }
            }

            if (population >= 1000000) {
                Console.WriteLine( Math.Sqrt(pos).ToString().Replace(',','.')); }
            else { Console.WriteLine("-1"); }

           //Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long  population = long.Parse(s[1]);
           // ArrayList R = new ArrayList();
            long[] rank = new long[200000000];
            long x = 0, y = 0;

            for (long i = 1; i <= n; i++) {
                s = Console.ReadLine().Split(' ');
                x = long.Parse(s[0]); y = long.Parse(s[1]);
                //if() R.Add(x * x + y * y);
                rank[x * x + y * y] += long.Parse(s[2]);
            }

            //R.Sort();
            double pos = 0;
            if (population < 1000000)
            {
                for (long i = 0; i < 200000000; i++)
                {
                    population += rank[i];
                    if (population >= 1000000) { pos = i; break; }
                }
            }

            if (population >= 1000000) { Console.WriteLine( Math.Sqrt(pos).ToString().Replace(',','.')); }
            else { Console.WriteLine("-1"); }

          // Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            long  population = long.Parse(s[1]);
            ArrayList R = new ArrayList();
            int[] rank = new int[15000];
            int x = 0, y = 0;

            for (int i = 1; i <= n; i++) {
                s = Console.ReadLine().Split(' ');
                x = int.Parse(s[0]); y = int.Parse(s[1]);
                R.Add(x * x + y * y);
                rank[x * x + y * y] += int.Parse(s[2]);
            }

            R.Sort();
            int pos = 0;
            for (int i = 0; i < n; i++) {
                population += rank[(int)R[i]];
                if (population >= 1000000) { pos = i; break; }
            }

            if (population >= 1000000) { Console.WriteLine( Math.Sqrt((int)R[pos]).ToString().Replace(',','.')); }
            else { Console.WriteLine("-1"); }

           //Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {

            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int  population = int.Parse(s[1]);
            ArrayList radius = new ArrayList();
            ArrayList rank = new ArrayList();

            int x = 0, y = 0,r=0,indx=0;
            int max = 0;

            for (long i = 0; i < n; i++) {
                string[] ss = Console.ReadLine().Split(' ');
                x = int.Parse(ss[0]); y = int.Parse(ss[1]);
                r = x*x +y*y ;
                max = (max < r) ? r : max;
                indx = radius.IndexOf(r);
                if (indx >= 0) { rank[indx] = (int)rank[indx] + int.Parse(ss[2]); }
                else { radius.Add(r); rank.Add(int.Parse(ss[2])) ; }

            }

            ArrayList rr = new ArrayList();
            rr.AddRange(radius);
            rr.Sort();

            int pos = 0;
            if (population < 1000000)
            {
                foreach(object o in rr )
                {
                    indx = radius.IndexOf((int)o);
                    population += (int)rank[indx];
                    if (population >= 1000000) { pos =(int)radius[indx]; break; }
                }
            }

            if (population >= 1000000) {
                Console.WriteLine( Math.Sqrt(pos).ToString().Replace(',','.')); }
            else { Console.WriteLine("-1"); }

           //Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long  population = long.Parse(s[1]);
           // ArrayList R = new ArrayList();
            long[] rank = new long[15000];
            long x = 0, y = 0;

            for (long i = 1; i <= n; i++) {
                s = Console.ReadLine().Split(' ');
                x = long.Parse(s[0]); y = long.Parse(s[1]);
                //if() R.Add(x * x + y * y);
                rank[x * x + y * y] += int.Parse(s[2]);
            }

            //R.Sort();
            double pos = 0;
            if (population < 1000000)
            {
                for (long i = 0; i < 15000; i++)
                {
                    population += rank[i];
                    if (population >= 1000000) { pos = i; break; }
                }
            }

            if (population >= 1000000) { Console.WriteLine( Math.Sqrt(pos).ToString().Replace(',','.')); }
            else { Console.WriteLine("-1"); }

          // Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {

            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int  population = int.Parse(s[1]);
            string[] list = new string[n] ;

            int x = 0, y = 0;
            int max = 0;
            for (long i = 0; i < n; i++)
            {
                list[i] = Console.ReadLine();
                string[] ss = list[i].Split(' ');
                x = int.Parse(ss[0]); y = int.Parse(ss[1]);
                max = (max < x * x + y * y) ? x * x + y * y : max;

            }

            int[] rank = new int[max+1];

            for (long i = 0; i < n; i++) {
                string[] ss = list[i].Split(' ');
                x = int.Parse(ss[0]); y = int.Parse(ss[1]);
                //if() R.Add(x * x + y * y);
                rank[(x * x) + (y * y)] += int.Parse(ss[2]);
            }

            //R.Sort();
            int pos = 0;
            if (population < 1000000)
            {
                for (int i = 0; i <= max; i++)
                {
                    population += rank[i];
                    if (population >= 1000000) { pos = i; break; }
                }
            }

            if (population >= 1000000) { Console.WriteLine( Math.Sqrt(pos).ToString().Replace(',','.')); }
            else { Console.WriteLine("-1"); }

           //Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            long  population = long.Parse(s[1]);
            ArrayList R = new ArrayList();
            int[] rank = new int[15000];
            int x = 0, y = 0;

            for (int i = 1; i <= n; i++) {
                s = Console.ReadLine().Split(' ');
                x = int.Parse(s[0]); y = int.Parse(s[1]);
                R.Add(x * x + y * y);
                rank[x * x + y * y] += int.Parse(s[2]);
            }

            R.Sort();
            int pos = 0;
            for (int i = 0; i < n; i++) {
                population += rank[(int)R[i]];
                if (population >= 1000000) { pos = i; break; }
            }

            if (population >= 1000000) { Console.WriteLine( Math.Sqrt((int)R[pos]).ToString("#.0000000") ); }
            else { Console.WriteLine("-1"); }

           //Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            long  population = long.Parse(s[1]);
            ArrayList R = new ArrayList();
            int[] rank = new int[15000];
            int x = 0, y = 0;

            for (int i = 1; i <= n; i++) {
                s = Console.ReadLine().Split(' ');
                x = int.Parse(s[0]); y = int.Parse(s[1]);
                R.Add(x * x + y * y);
                rank[x * x + y * y] += int.Parse(s[2]);
            }

            R.Sort();
            int pos = 0;
            for (int i = 0; i < n; i++) {
                population += rank[(int)R[i]];
                if (population >= 1000000) { pos = i; break; }
            }

            if (population >= 1000000) { Console.WriteLine( Math.Sqrt((int)R[pos])); }
            else { Console.WriteLine("-1"); }

           // Main(new string[0]);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            long  population = long.Parse(s[1]);
           // ArrayList R = new ArrayList();
            int[] rank = new int[15000];
            int x = 0, y = 0;

            for (int i = 1; i <= n; i++) {
                s = Console.ReadLine().Split(' ');
                x = int.Parse(s[0]); y = int.Parse(s[1]);
                //if() R.Add(x * x + y * y);
                rank[x * x + y * y] += int.Parse(s[2]);
            }

            //R.Sort();
            int pos = 0;
            for (int i = 0; i < 15000; i++) {
                population += rank[i];
                if (population >= 1000000) { pos = i; break; }
            }

            if (population >= 1000000) { Console.WriteLine( Math.Sqrt(pos).ToString().Replace(',','.')); }
            else { Console.WriteLine("-1"); }

          // Main(new string[0]);

        }
    }
}


// Submitted by Silithus @ Macau
using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;
using CCF_XOI;

namespace CodeForces
{
	class CF424B
	{
		struct one_city
		{
			public int k;
			public double r;

			public static int CompareByR(one_city x, one_city y)
			{
				return x.r.CompareTo(y.r);
			}
		}

		public void Solve(XOI xoi)
		{
			int N, sum, i, x, y;
			one_city[] c;
			CultureInfo enUS = CultureInfo.CreateSpecificCulture("en-US");

			N = xoi.ReadInt();
			sum = xoi.ReadInt();
			c = new one_city[N];

			for (i = 0; i < N; i++)
			{
				x = xoi.ReadInt();
				y = xoi.ReadInt();
				c[i].k = xoi.ReadInt();
				c[i].r = (double)(x * x) + (double)(y * y);
			}
			Array.Sort(c, one_city.CompareByR);

			for (i = 0; i < N && sum < 1000000; i++)
				sum += c[i].k;

			if (sum >= 1000000)
				xoi.o.WriteLine(Math.Sqrt(c[i - 1].r).ToString("F7", enUS));
			else
				xoi.o.WriteLine("-1");
		}
	}

	class CodeForcesMain
	{
		static void Main(string[] args)
		{
			(new CF424B()).Solve(new XOI());
		}
	}
}

namespace CCF_XOI
{	// version 2014.02.07
	class XOI
	{
		protected StreamReader sr;
		public StreamWriter o;
		protected Queue<string> buf = new Queue<string>();
		public bool EOF = false;

		public XOI()
		{
			this.sr = new StreamReader(Console.OpenStandardInput());
			this.o = new StreamWriter(Console.OpenStandardOutput());
			this.o.AutoFlush = true;
		}

		public XOI(string in_path, string out_path)
		{
			this.sr = new StreamReader(in_path);
			this.o = new StreamWriter(out_path);
			this.o.AutoFlush = true;
		}

		public int ReadInt()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Int32.Parse(s);
		}

		public long ReadLong()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Int64.Parse(s);
		}

		public double ReadDouble()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Double.Parse(s);
		}

		public string ReadString()
		{
			string s = this.GetNext();
			return (s == null ? null : s);
		}

		public string ReadLine()
		{	// I will ignore current buffer and read a new line
			string s = "";
			while (s == "" && !this.EOF)
			{
				s = sr.ReadLine();
				this.EOF = (s == null);
			}
			return (this.EOF ? null : s);
		}

		protected string GetNext()
		{
			if (buf.Count == 0)
			{
				while (buf.Count == 0 && !this.EOF)
				{
					string s = sr.ReadLine();
					if (s == null)
						this.EOF = true;
					else
						foreach (string ss in s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
							buf.Enqueue(ss);
				}
			}

			return (this.EOF ? null : buf.Dequeue());
		}
	}
}


// Submitted by Silithus @ Macau
using System;
using System.IO;
using System.Collections.Generic;
using CCF_XOI;

namespace CodeForces
{
	class CF424B
	{
		struct one_city
		{
			public int k;
			public double r;

			public static int CompareByR(one_city x, one_city y)
			{
				return x.r.CompareTo(y.r);
			}
		}

		public void Solve(XOI xoi)
		{
			int N, sum, i, x, y;
			one_city[] c;

			N = xoi.ReadInt();
			sum = xoi.ReadInt();
			c = new one_city[N];

			for (i = 0; i < N; i++)
			{
				x = xoi.ReadInt();
				y = xoi.ReadInt();
				c[i].k = xoi.ReadInt();
				c[i].r = (double)(x * x) + (double)(y * y);
			}
			Array.Sort(c, one_city.CompareByR);

			for (i = 0; i < N && sum < 1000000; i++)
				sum += c[i].k;

			if (sum >= 1000000)
				xoi.o.WriteLine(Math.Sqrt(c[i - 1].r).ToString("F7"));
			else
				xoi.o.WriteLine("-1");
		}
	}

	class CodeForcesMain
	{
		static void Main(string[] args)
		{
			(new CF424B()).Solve(new XOI());
		}
	}
}

namespace CCF_XOI
{	// version 2014.02.07
	class XOI
	{
		protected StreamReader sr;
		public StreamWriter o;
		protected Queue<string> buf = new Queue<string>();
		public bool EOF = false;

		public XOI()
		{
			this.sr = new StreamReader(Console.OpenStandardInput());
			this.o = new StreamWriter(Console.OpenStandardOutput());
			this.o.AutoFlush = true;
		}

		public XOI(string in_path, string out_path)
		{
			this.sr = new StreamReader(in_path);
			this.o = new StreamWriter(out_path);
			this.o.AutoFlush = true;
		}

		public int ReadInt()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Int32.Parse(s);
		}

		public long ReadLong()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Int64.Parse(s);
		}

		public double ReadDouble()
		{
			string s = this.GetNext();
			if (s == null) return -1;
			else return Double.Parse(s);
		}

		public string ReadString()
		{
			string s = this.GetNext();
			return (s == null ? null : s);
		}

		public string ReadLine()
		{	// I will ignore current buffer and read a new line
			string s = "";
			while (s == "" && !this.EOF)
			{
				s = sr.ReadLine();
				this.EOF = (s == null);
			}
			return (this.EOF ? null : s);
		}

		protected string GetNext()
		{
			if (buf.Count == 0)
			{
				while (buf.Count == 0 && !this.EOF)
				{
					string s = sr.ReadLine();
					if (s == null)
						this.EOF = true;
					else
						foreach (string ss in s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
							buf.Enqueue(ss);
				}
			}

			return (this.EOF ? null : buf.Dequeue());
		}
	}
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;

namespace Megacity
{
    internal class Program
    {
        private static readonly StreamReader reader =
            new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);

        private static readonly StreamWriter writer =
            new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

        private static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            string[] ss = reader.ReadLine().Split(' ');
            int n = int.Parse(ss[0]);
            int s = int.Parse(ss[1]);

            List<town> towns = new List<town>(n);
            for (int i = 0; i < n; i++)
            {
                ss = reader.ReadLine().Split(' ');
                towns.Add(new town(int.Parse(ss[0]), int.Parse(ss[1]), int.Parse(ss[2])));
            }
            towns.Sort(towns[0]);

            bool f = false;
            double r = 0;

            foreach (var town in towns)
            {
                s += town.p;
                if (s>=1000000)
                {
                    f = true;
                    r = town.r;
                    break;
                }
            }
            if (f)
            writer.WriteLine("{0:#.0000000}",r);
            else
            {
                writer.WriteLine(-1);
            }
            writer.Flush();
        }

        class town:IComparer<town>
        {
            public int p;
            public double r;

            public town(int x,int y, int p)
            {
                this.p = p;
                r = Math.Sqrt(x*x + y*y);
            }

            public int Compare(town x, town y)
            {
                return x.r.CompareTo(y.r);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;

namespace Megacity
{
    internal class Program
    {
        private static readonly StreamReader reader =
            new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);

        private static readonly StreamWriter writer =
            new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            string[] ss = reader.ReadLine().Split(' ');
            int n = int.Parse(ss[0]);
            int s = int.Parse(ss[1]);

            var towns = new List<town>(n);
            for (int i = 0; i < n; i++)
            {
                ss = reader.ReadLine().Split(' ');
                towns.Add(new town(int.Parse(ss[0]), int.Parse(ss[1]), int.Parse(ss[2])));
            }
            towns.Sort(towns[0]);

            bool f = false;
            double r = 0;

            foreach (town town in towns)
            {
                s += town.p;
                if (s >= 1000000)
                {
                    f = true;
                    r = town.r;
                    break;
                }
            }
            if (f)
                writer.WriteLine("{0}", r.ToString("#.0000000", CultureInfo.GetCultureInfo("en-US")));
            else
            {
                writer.WriteLine(-1);
            }
            writer.Flush();
        }

        #region Nested type: town

        private class town : IComparer<town>
        {
            public readonly int p;
            public readonly double r;

            public town(int x, int y, int p)
            {
                this.p = p;
                r = Math.Sqrt(x*x + y*y);
            }

            #region IComparer<town> Members

            public int Compare(town x, town y)
            {
                return x.r.CompareTo(y.r);
            }

            #endregion
        }

        #endregion
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;

namespace Megacity
{
    internal class Program
    {
        private static readonly StreamReader reader =
            new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);

        private static readonly StreamWriter writer =
            new StreamWriter(Console.OpenStandardOutput(1024 * 10), Encoding.ASCII, 1024 * 10);

        private static void Main(string[] args)
        {
            //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            string[] ss = reader.ReadLine().Split(' ');
            int n = int.Parse(ss[0]);
            int s = int.Parse(ss[1]);

            List<town> towns = new List<town>(n);
            for (int i = 0; i < n; i++)
            {
                ss = reader.ReadLine().Split(' ');
                towns.Add(new town(int.Parse(ss[0]), int.Parse(ss[1]), int.Parse(ss[2])));
            }
            towns.Sort(towns[0]);

            bool f = false;
            double r = 0;

            foreach (var town in towns)
            {
                s += town.p;
                if (s>=1000000)
                {
                    f = true;
                    r = town.r;
                    break;
                }
            }
            if (f)
            writer.WriteLine("{0:#.0000000}",r);
            else
            {
                writer.WriteLine(-1);
            }
            writer.Flush();
        }

        class town:IComparer<town>
        {
            public int p;
            public double r;

            public town(int x,int y, int p)
            {
                this.p = p;
                r = Math.Sqrt(x*x + y*y);
            }

            public int Compare(town x, town y)
            {
                return x.r.CompareTo(y.r);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MillionaireCity
{
    public struct Settlement
    {
        int x;
        int y;
        int k;
        double r;

        public int X { get; set;}
        public int Y { get; set; }
        public int Population {
            get
            {
                return k;
            }
            set
            {
                k = value;
            }
        }
        public double DistanceToMainCity
        {
            get
            {
                return Math.Sqrt(X*X + Y*Y);
            }
        }
    }

    class Program
    {
        public static void QuickSort(Settlement[] elements, int left, int right)
        {
            int i = left, j = right;
            Settlement pivot = elements[(left + right)/2];

            while (i <= j)
            {
                while (elements[i].DistanceToMainCity.CompareTo(pivot.DistanceToMainCity) < 0)
                {
                    i++;
                }

                while (elements[j].DistanceToMainCity.CompareTo(pivot.DistanceToMainCity) > 0)
                {
                    j--;
                }

                if (i <= j)
                {
                    // Swap
                    Settlement tmp = elements[i];
                    elements[i] = elements[j];
                    elements[j] = tmp;

                    i++;
                    j--;
                }
            }

            // Recursive calls
            if (left < j)
            {
                QuickSort(elements, left, j);
            }

            if (i < right)
            {
                QuickSort(elements, i, right);
            }

        }

        public static void MinRadius()
        {
        //    Console.WriteLine("Input count of settlements and population of main city:");
            string input = Console.ReadLine();
            string[] ns = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int n = Convert.ToInt32(ns[0]);
            int s =  Convert.ToInt32(ns[1]);

            Settlement[] settlements = new Settlement[n];
            IComparable[] radiuses = new IComparable[n];

         //   Console.WriteLine("Input coordinates (x,y) and population k of settlements");
            for (int i = 0; i < n; i++)
            {
                string settlementInfo = Console.ReadLine();
                string[] settlementInfoElem = settlementInfo.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                settlements[i].X = Convert.ToInt32(settlementInfoElem[0]);
                settlements[i].Y = Convert.ToInt32(settlementInfoElem[1]);
                settlements[i].Population = Convert.ToInt32(settlementInfoElem[2]); ;
            }

            QuickSort(settlements, 0, n - 1);

            int population = 0;
            for (int i = 0; i < n; i++)
            {
                population += settlements[i].Population;
                if ((s + population) >= 1000000)
                {
                    Console.Write(String.Format("{0:0.0000000}", settlements[i].DistanceToMainCity));
                    break;
                }
                else
                {
                    if (i == n - 1)
                        Console.WriteLine("-1");
                }

            }
        }

        static void Main(string[] args)
        {
           MinRadius();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MillionaireCity
{
    public struct Settlement
    {
        int x;
        int y;
        int k;
        double r;

        public int X { get; set;}
        public int Y { get; set; }
        public int Population {
            get
            {
                return k;
            }
            set
            {
                k = value;
            }
        }
        public double DistanceToMainCity
        {
            get
            {
                return Math.Sqrt(X*X + Y*Y);
            }
        }
    }

    class Program
    {
        public static void QuickSort(Settlement[] elements, int left, int right)
        {
            int i = left, j = right;
            Settlement pivot = elements[(left + right)/2];

            while (i <= j)
            {
                while (elements[i].DistanceToMainCity.CompareTo(pivot.DistanceToMainCity) < 0)
                {
                    i++;
                }

                while (elements[j].DistanceToMainCity.CompareTo(pivot.DistanceToMainCity) > 0)
                {
                    j--;
                }

                if (i <= j)
                {
                    // Swap
                    Settlement tmp = elements[i];
                    elements[i] = elements[j];
                    elements[j] = tmp;

                    i++;
                    j--;
                }
            }

            // Recursive calls
            if (left < j)
            {
                QuickSort(elements, left, j);
            }

            if (i < right)
            {
                QuickSort(elements, i, right);
            }

        }

        public static void MinRadius()
        {
            Console.WriteLine("Input count of settlements and population of main city:");
            string input = Console.ReadLine();
            string[] ns = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int n = Convert.ToInt32(ns[0]);
            int s =  Convert.ToInt32(ns[1]);

            Settlement[] settlements = new Settlement[n];
            IComparable[] radiuses = new IComparable[n];

            Console.WriteLine("Input coordinates (x,y) and population k of settlements");
            for (int i = 0; i < n; i++)
            {
                string settlementInfo = Console.ReadLine();
                string[] settlementInfoElem = settlementInfo.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                settlements[i].X = Convert.ToInt32(settlementInfoElem[0]);
                settlements[i].Y = Convert.ToInt32(settlementInfoElem[1]);
                settlements[i].Population = Convert.ToInt32(settlementInfoElem[2]); ;
            }

            QuickSort(settlements, 0, n - 1);

            int population = 0;
            for (int i = 0; i < n; i++)
            {
                population += settlements[i].Population;
                if ((s + population) >= 1000000)
                {
                    Console.Write(String.Format("{0:0.0000000}", settlements[i].DistanceToMainCity));
                    break;
                }
                else
                {
                    if (i == n - 1)
                        Console.WriteLine("-1");
                }

            }
        }

        static void Main(string[] args)
        {
           MinRadius();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace MillionaireCity
{
    public struct Settlement
    {
        int x;
        int y;
        int k;
        double r;

        public int X { get; set;}
        public int Y { get; set; }
        public int Population {
            get
            {
                return k;
            }
            set
            {
                k = value;
            }
        }
        public double DistanceToMainCity
        {
            get
            {
                return Math.Sqrt(X*X + Y*Y);
            }
        }
    }

    class Program
    {
        public static void QuickSort(Settlement[] elements, int left, int right)
        {
            int i = left, j = right;
            Settlement pivot = elements[(left + right)/2];

            while (i <= j)
            {
                while (elements[i].DistanceToMainCity.CompareTo(pivot.DistanceToMainCity) < 0)
                {
                    i++;
                }

                while (elements[j].DistanceToMainCity.CompareTo(pivot.DistanceToMainCity) > 0)
                {
                    j--;
                }

                if (i <= j)
                {
                    // Swap
                    Settlement tmp = elements[i];
                    elements[i] = elements[j];
                    elements[j] = tmp;

                    i++;
                    j--;
                }
            }

            // Recursive calls
            if (left < j)
            {
                QuickSort(elements, left, j);
            }

            if (i < right)
            {
                QuickSort(elements, i, right);
            }

        }

        public static void MinRadius()
        {
        //    Console.WriteLine("Input count of settlements and population of main city:");
            string input = Console.ReadLine();
            string[] ns = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int n = Convert.ToInt32(ns[0]);
            int s =  Convert.ToInt32(ns[1]);

            Settlement[] settlements = new Settlement[n];
            IComparable[] radiuses = new IComparable[n];

         //   Console.WriteLine("Input coordinates (x,y) and population k of settlements");
            for (int i = 0; i < n; i++)
            {
                string settlementInfo = Console.ReadLine();
                string[] settlementInfoElem = settlementInfo.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                settlements[i].X = Convert.ToInt32(settlementInfoElem[0]);
                settlements[i].Y = Convert.ToInt32(settlementInfoElem[1]);
                settlements[i].Population = Convert.ToInt32(settlementInfoElem[2]); ;
            }

            QuickSort(settlements, 0, n - 1);

            int population = 0;
            for (int i = 0; i < n; i++)
            {
                population += settlements[i].Population;
                if ((s + population) >= 1000000)
                {
                           Console.WriteLine(settlements[i].DistanceToMainCity.ToString("F7", CultureInfo.CreateSpecificCulture("en-US")));
                    break;
                }
                else
                {
                    if (i == n - 1)
                        Console.WriteLine("-1");
                }

            }
        }

        static void Main(string[] args)
        {
           MinRadius();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
using System.Security.Principal;
using System.Text;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Collections;
using System.Text.RegularExpressions;

namespace Task
{

    #region MyIo

    internal class MyIo : IDisposable
    {
#if  LOCAL_TEST
        private readonly TextReader inputStream = new StreamReader("input.txt");
#else
        private readonly TextReader inputStream = Console.In;
#endif
#if  FBHC_TEST
        private readonly TextWriter outputStream = new StreamWriter("output.txt");
#else
        private readonly TextWriter outputStream = Console.Out;
#endif

        private string[] tokens;
        private int pointer;

        public char NextChar()
        {
            try
            {
                var c = inputStream.Read();

                if (c < 0)
                    c = 0;

                return (char)c;
            }
            catch (IOException)
            {
                return '\0';
            }
        }

        public string NextLine()
        {
            try
            {
                return inputStream.ReadLine();
            }
            catch (IOException)
            {
                return null;
            }
        }

        public string NextString()
        {
            try
            {
                while (tokens == null || pointer >= tokens.Length)
                {
                    tokens = (NextLine() + string.Empty).Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    pointer = 0;
                }
                return tokens[pointer++];
            }
            catch (IOException)
            {
                return null;
            }
        }

        public int NextInt()
        {
            return Next<int>();
        }

        public long NextLong()
        {
            return Next<long>();
        }

        public T Next<T>()
        {
            var t = typeof(T);

            if (t == typeof(char))
                return (T)(object)NextChar();

            object s = NextString();

            if (t == typeof(string))
                return (T)s;

            return (T)Convert.ChangeType(s, typeof(T));
        }

        public IEnumerable<T> NextWhile<T>(Predicate<T> pred)
        {
            if (pred == null)
                yield break;

            var res = Next<T>();

            while (pred(res))
            {
                yield return res;

                res = Next<T>();
            }
        }

        public IEnumerable<T> NextSeq<T>(long n)
        {
            for (var i = 0; i < n; i++)
                yield return Next<T>();
        }

        public void Print(string format, params object[] args)
        {
            outputStream.Write(string.Format(CultureInfo.InvariantCulture, format, args));
        }

        public void PrintLine(string format, params object[] args)
        {
            Print(format, args);

            outputStream.WriteLine();
        }

        public void Print(bool o)
        {
            Print(o ? "YES" : "NO");
        }

        public void PrintLine(bool o)
        {
            Print(o);

            outputStream.WriteLine();
        }

        public void Print<T>(T o)
        {
            var ienum = o as IEnumerable;

            if (ienum != null && typeof(T) != typeof(string))
            {
                var first = true;

                foreach (var iev in ienum)
                {
                    if (!first && iev != null)
                        Print(" ");

                    Print(iev);

                    first = false;
                }

            }
            else
            {
                outputStream.Write(Convert.ToString(o, CultureInfo.InvariantCulture));
            }

        }

        public void PrintLine<T>(T o)
        {
            Print(o);

            outputStream.WriteLine();
        }

        public void Close()
        {
            inputStream.Close();
            outputStream.Close();
        }

        void IDisposable.Dispose()
        {
            Close();

#if  LOCAL_TEST
            Console.ReadLine();
#endif
        }
    }

    public static class ListExtensions
    {
        public static void Each<T>(this IEnumerable<T> self, Action<T> action)
        {
            foreach (var v in self)
                action(v);
        }

        public static string Reverse(this string s)
        {
            var charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }

        public static IEnumerable<T> ToCycleEnumerable<T>(this IEnumerable<T> self)
        {
            if (self != null)
            {
                for (; ; )
                {
                    foreach (var x in self)
                        yield return x;
                }
            }
        }

        public static T CycleGet<T>(this IList<T> self, int index)
        {
            var c = self.Count;
            return self[(index % c + c) % c];
        }

        public static IList<T> Shuffle<T>(this IList<T> self)
        {
            var rnd = new Random(DateTime.Now.Millisecond);

            var n = self.Count;

            while (n > 1)
            {
                n--;
                var k = rnd.Next(n + 1);
                var value = self[k];
                self[k] = self[n];
                self[n] = value;
            }

            return self;
        }

        public static IList<IList<T>> UseForNew2D<T>(this T def, int fd, int sd)
        {
            var fdim = new T[fd][];

            for (int i = 0; i < fd; i++)
            {
                fdim[i] = new T[sd];
                Fill(fdim[i], def);
            }

            return fdim;
        }

        public static IList<T> Fill<T>(this IList<T> self, Func<int, IList<T>, T> fval)
        {
            for (var i = 0; i < self.Count; i++)
                self[i] = fval(i, self);

            return self;
        }

        public static IList<T> Fill<T>(this IList<T> self, Func<int, T> fval)
        {
            return self.Fill((x, slf) => fval(x));
        }

        public static IList<T> Fill<T>(this IList<T> self, Func<T> fval)
        {
            return self.Fill(x => fval());
        }

        public static IList<T> Fill<T>(this IList<T> self, T val)
        {
            return self.Fill(() => val);
        }

        public static long Hash<T>(this IList<T> self, Func<T, long> val = null)
        {
            return val != null ? self.Hash((t, current) => unchecked(current * 19L + val(t))) : self.Hash(HashOne);
        }

        public static long Hash<T>(this IList<T> self, Func<T, long, long> val)
        {
            return self.Aggregate(0L, (current, t) => unchecked(val(t, current)));
        }

        public static long HashOne<T>(this T self, long current)
        {
            return unchecked(current * 19L + (Equals(self, default(T)) ? 0 : self.GetHashCode()));
        }

        public static IList<T1> BuildSegTree<T1, T2>(this IList<T2> a, Func<T1, T1, T1> combine, Func<T2, T1> convert)
        {
            var t = new T1[a.Count << 2];

            a.BuildSegTree(t, 1, 0, a.Count - 1, combine, convert);

            return t;
        }

        private static void BuildSegTree<T1, T2>(this IList<T2> a, IList<T1> t, int v, int tl, int tr, Func<T1, T1, T1> combine, Func<T2, T1> convert)
        {
            if (tl == tr)
            {
                t[v] = convert(a[tl]);
            }
            else
            {
                int tm = (tl + tr) >> 1;

                BuildSegTree(a, t, v << 1, tl, tm, combine, convert);
                BuildSegTree(a, t, (v << 1) + 1, tm + 1, tr, combine, convert);

                t[v] = combine(t[v << 1], t[(v << 1) + 1]);
            }
        }
    }

    public static class P
    {
        public static P<T1, T2> Create<T1, T2>(T1 key, T2 val)
        {
            return new P<T1, T2>(key, val);
        }
    }

    public class P<T1, T2>
    {
        private class PComparer : IComparer<P<T1, T2>>
        {
            private readonly bool? byKey;

            public PComparer(bool? byKey)
            {
                this.byKey = byKey;
            }

            public int Compare(P<T1, T2> x, P<T1, T2> y)
            {
                x = x ?? new P<T1, T2>();
                y = y ?? new P<T1, T2>();

                if (byKey == true)
                    return Comparer<T1>.Default.Compare(x.Key, y.Key);
                else if (byKey == false)
                    return Comparer<T2>.Default.Compare(x.Value, y.Value);
                else
                {
                    var tr = Comparer<T1>.Default.Compare(x.Key, y.Key);

                    if (tr != 0)
                        tr = Comparer<T2>.Default.Compare(x.Value, y.Value);

                    return tr;
                }
            }
        }

        public P()
        {
        }

        public P(T1 key, T2 val)
        {
            this.Key = key;
            this.Value = val;
        }

        public T1 Key
        {
            get;
            set;
        }

        public T2 Value
        {
            get;
            set;
        }

        public P<T1, T2> Clone()
        {
            return new P<T1, T2>(Key, Value);
        }

        public static IComparer<P<T1, T2>> KeyComparer
        {
            get { return new PComparer(true); }
        }

        public static IComparer<P<T1, T2>> ValueComparer
        {
            get { return new PComparer(false); }
        }

        public static implicit operator T1(P<T1, T2> obj)
        {
            return obj.Key;
        }

        public static implicit operator T2(P<T1, T2> obj)
        {
            return obj.Value;
        }

        public P<T1, T2> SetKey(T1 key)
        {
            Key = key;
            return this;
        }

        public P<T1, T2> SetValue(T2 value)
        {
            Value = value;
            return this;
        }

        public override string ToString()
        {
            return string.Format("Key: {0}, Value: {1}", Key, Value);
        }

        public override bool Equals(object obj)
        {
            var co = obj as P<T1, T2>;

            return co != null && co.GetHashCode() == GetHashCode();
        }

        public override int GetHashCode()
        {
            int hash = 17;
            hash = unchecked(hash * 31 + ((Equals(Key, default(T1))) ? 0 : Key.GetHashCode()));
            hash = unchecked(hash * 31 + ((Equals(Value, default(T1))) ? 0 : Value.GetHashCode()));
            return hash;

        }
    }

    #endregion

    internal class Program
    {
        #region Program

        private readonly MyIo io;

        public Program(MyIo io)
        {
            this.io = io;
        }

        public static void Main(string[] args)
        {
            using (MyIo io = new MyIo())
            {
                new Program(io)
                    .Solve();
            }
        }

        #endregion

        private void Solve()
        {
            var n = io.NextInt();
            var s = io.NextInt();

            var i = new Dictionary<double, int>();

            for (int j = 0; j < n; j++)
            {
                var x = io.NextLong();
                var y = io.NextLong();

                var z = io.NextInt();

                var k = Math.Sqrt(x*x + y*y);

                if (!i.ContainsKey(k))
                    i.Add(k, z);
                else
                    i[k] += z;
            }

            i.Add(0, s);

            var xn = 0;

            foreach (var kvp in i.OrderBy(x => x.Key))
            {
                xn += kvp.Value;

                if (xn >= 1000000)
                {
                    io.Print(kvp.Key);
                    return;
                }

            }

            io.Print(-1);

        }
    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _415
{
    class B
    {
        class Scanner
        {
            string[] s;
            int i;

            char[] cs = new char[] { ' ' };

            public Scanner()
            {
                //s = @"5 5 5 4 3 2 1".Split(cs, StringSplitOptions.RemoveEmptyEntries);
                s = new string[0];
                i = 0;
            }

            public string next()
            {
                if (i < s.Length) return s[i++];
                s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
                i = 0;
                return s[i++];
            }

            public int nextInt()
            {
                return int.Parse(next());
            }

            public long nextLong()
            {
                return long.Parse(next());
            }
        }

        static void Main(string[] args)
        {
            var stream = new Scanner();
            int n = stream.nextInt(); // number of villages
            int s = stream.nextInt(); // population on Tomsk

            int x, y;
            double r;
            double[] radiusMass = new double[n];
            int[] inputMass = new int[n];

            for (int i = 0; i < n; i++)
            {
                x = stream.nextInt();
                y = stream.nextInt();
                r = Math.Sqrt(x * x + y * y);
                radiusMass[i] = r;
                inputMass[i] = stream.nextInt();
            }

            double locVar = 0;
            int locVar2 = 0;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n-1; j++)
                {
                    if (radiusMass[j] > radiusMass[j + 1])
                    {
                        locVar = radiusMass[j];
                        radiusMass[j] = radiusMass[j + 1];
                        radiusMass[j + 1] = locVar;

                        locVar2 = inputMass[j];
                        inputMass[j] = inputMass[j + 1];
                        inputMass[j + 1] = locVar2;
                    }
                }

            int population = s;
            int counter = 0;
            double result = -1;
            while (s < 1000000)
            {
                s = s + inputMass[counter];
                counter++;
                if (counter == n)
                {
                    Console.Write("-1 ");
                    return;
                }
            }

            counter--;
            result = Math.Round(radiusMass[counter],9);
            //result = radiusMass[counter];
            //Console.WriteLine(result);
            //Console.WriteLine(String.Format("{0:F9}", result));
            string res = result.ToString();
            Console.WriteLine("{0:R}", res);
            Console.Out.Flush();

            //Console.Write(resultMass[i] + " ");
        }
    }
}