That’s tough luck. Since you didn’t in fact commit the first crime and were in fact nowhere near where it happened the prosecutor shouldn’t logically be able to prove your guilt beyond reasonable doubt. But depending on the circumstances, they might (if you had motive, opportunity etc. )
You might hire a private detective to find evidence that you were not at the place if the crime (for example a CCTV camera catching you 50m from the location of the second crime). Your lawyer might be able to put your alibi in such a way that it doesn’t incriminate you enough for a conviction. And since you know that every witness of the first crime against is lying or mistaken, your private detective and/or lawyer will find it easier to demonstrate that.
Worst case, judge and jury might not be willing to believe your alibi without proof. So you might be forced to not just admit the second crime but show evidence that you did it. Like producing jewellery stolen in town B might be needed to prove that you didn’t commit a murder in town A.
You can’t be forced to self-incriminate but there may be rare situations where it is your best choice. Tough luck.