I don’t know enough java to be able to test your program, but I suspect this bit.
} else {
males.add(first);
females.add(second);
}
You don’t yet know anything about the first or second bugs, so you arbitrarily assign one as male and the other as female, but you might find information further into the data that lets you know for sure.
What does your code say for this case?
1
8 4
1 2
3 4
6 5
8 7
3 6
4 5