For this Question: Given a undirected graph with N nodes and M edges. Find the maximum number of edges that you can remove, so that the graph is still connected. If there does not exist any way, print -1. The graph could contain self loops and multiple edges.The first line of input contains four space- separated integers N and M.
Next M lines contain two integers u and v each, denoting that there is an edge from node u to node v.

Constraints:-
1 <= N <= 100000
1 <= M <= 200000
1<= u, v <= NPrint a single integer denoting the maximum number of edges you can remove, so that the graph is still connected.Sample Input 1:
3 3
1 2
2 3
3 3

Output 
1

Explanation:
You can remove the edge (3,3).

Sample Input 2:
5 3
1 2
2 3
3 4

Output
-1

Explanation
The graph is disconnected initially and there are no ways we could remove edges and the graph becomes connected., I have written this Solution Code: import java.io.*;
import java.util.*;

class Main
{
    static ArrayList<ArrayList<Integer> > g= new ArrayList<ArrayList<Integer> >(100001);
    static int[] vis=new int[100001];
    static void dfs(int node) {
    	vis[node] = 1;
    	for (int i=0;i<g.get(node).size();i++) {
    		if (vis[g.get(node).get(i)]==0) {
    			dfs(g.get(node).get(i));
    		}
    	}
    }
    public static void main (String args[]) throws IOException
    {
        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        int n, m;
        String line = br.readLine();
    	String[] strs = line.trim().split("\\s+");
    	n=Integer.parseInt(strs[0]);
        m=Integer.parseInt(strs[1]);
        for(int i=0;i<n+1;i++)
        {
            g.add(new ArrayList<Integer>());
        }
    	for(int i=0;i<m;i++) {
    		int u, v;
    		line = br.readLine();
    		strs = line.trim().split("\\s+");
    		u=Integer.parseInt(strs[0]);
            v=Integer.parseInt(strs[1]);
            if(u!=v){
                (g.get(u)).add(v);
                (g.get(v)).add(u);
            }
    		
    	}
    	for(int i=0;i<n+1;i++){
    	    vis[i]=0;
    	}
    	dfs(1);
    	int ans = 1;
    	for (int i = 1; i <= n; i++) {
    		if (vis[i]==0) {
    			ans=-1;
    		}
    	}
    	if(ans==1){
    	    System.out.print(m-n+1);
    	}
    	else {
    	    System.out.print(-1);
    	}
    }
}
, In this Programming Language: Java, Now tell me if this Code is compilable or not?