In 2222, human has been highly developed in space. There are a lot of bases in the space. It was found that linking these bases is more conducive to human's development. Therefore, We need to calculate that the minimum number of roads we should build to connect all the bases, either connecting directly or not directly.
There are multiple cases.
For each case:
First line: two non-negative integers M (M <= 1000) and N, M means the number of bases, from 1 to M.
The next N lines: each line have two numbers A, B represents the existing road number.
when M = N = 0 means the end.
Print the number of road in one line.