Suppose that G has more than one cycle and let C be one of the cycles of G, if we remove one of the edges of C from G, then by our supposition the new graph G' would have a cycle. However, the number of edges of G' is equal to m-1=n-1 and G' has the same vertices of G, which means that n is the number of vertices of G. Therefore, the number of edges of G' is equal to the number of vertices of G' minus 1, which tells us that G' is a tree (it has no cycles), and so we get a contradiction.