#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int main()
{
	
	int n;
	long long sn, x, y;
	vector<long long>p;
	map<long, long>m;
	while (1){
		m.clear();
		p.clear();
		cin >> n;

		if (n == 0)break;
		for (int i = 0; i < n; i++){
		cin >> sn >> x >> y;
			if (m.find(sn) == m.end()){
				p.push_back(sn);
			}
				m[sn] += x*y;
		}
		int flag = 0;
		for (int i = 0; i < p.size(); i++){
			if (m[p[i]] >= 1000000){
				cout << p[i] << endl;
				flag++;
			}
		}
		if (flag==0)cout << "NA" << endl;
	}
}
#include<bits/stdc++.h>
using namespace std;
long long pd,n,s,p[200005],loc,num,l,r,ss;
long long ans,val[200005];
int main(){
//	freopen("go home.in","r",stdin);
//	freopen("go home.out","w",stdout);
	scanf("%lld%lld",&n,&s);
	pd=0;l=1;r=n+1;
	for (long long i=1;(i<=n);i++){
		scanf("%lld%lld",&loc,&num);
		if(pd==0)
			if (loc>=s){
				p[i]=s;val[i]=0;pd=1;ss=i;
			}
		p[i+pd]=loc;val[i+pd]=num;
	} 
	if (pd==0) p[n+1]=s;
	while (true){
		if (p[l]>=p[ss]){
			
			ans+=p[r]-p[l];
			printf("%lld",ans);
			return 0;
		}
		if (p[r]<=p[ss]){
			
			ans+=p[r]-p[l];
			printf("%lld",ans);
			return 0;
		}
		ans+=p[r]-p[l];
		if (val[l]>=val[r]){
			while (val[l]>=val[r]){
				val[l]+=val[r];
				r--;
				if (p[r]==p[ss]) break;
			}
			
		} else{
			while (val[r]>val[l]){
				val[r]+=val[l];
				l++;
				if (p[l]==p[ss]) break;
			}
		}
		
	}
	//fclose(stdin);fclose(stdout);
	return 0;
}