andrew and meat balls-runtime error

import java.io.BufferedReader;

import java.io.InputStreamReader;

class MeatBalls{

static int a[]=null;
static int n=0;
public static void main(String args[]) throws Exception{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	int T=Integer.parseInt(br.readLine());
	String s[]=null;
	while(T>0){
		s=br.readLine().split(" ");
		n=Integer.parseInt(s[0]);
		int m=Integer.parseInt(s[1]);
		s=br.readLine().split(" ");
		a=new int[n];
		int sum=0;
		for(int j=0;j<n;j++){
			a[j]=Integer.parseInt(s[j]);
			
		}
		sort();
		int i=0;
		for(i=n-1 ;i>=0 && sum<m;i--){
			sum=sum+a[i];
		}
		
		if(i<0 && sum<m)
			System.out.println(-1);
		else
			System.out.println(n-1-i);
		T--;
	
	}
	
}


public static void sort(){
	for(int i=0;i<n;i++){
		for(int j=0;j<n-1-i;j++){
			if(a[j+1]<a[j]){
				int t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;
			}
		}
	}
}

}