The crown of the UK is a union of the crowns of England and Scotland. (And maybe Ireland too but that's not relevant to this question.)
This means that the current Queen is "Queen Elizabeth II" for all of the UK because she is the 2nd Queen Elizabeth for the united crown, even though Scotland never had a 1st.
Similarly, the next James will be "King James IX"VIII". The two King James of England were numbered the 1st and 2nd, but they are the same individuals as the 7th6th and 8th7th King James of Scotland.
Both England and Scotland have had separate individuals named "Queen Mary I" of each country. When Queen Mary II became Queen of both England and Scotland, the two countries still had separate crowns. It was a coincidence that both countries each had one Mary as Queen so she was "The Second" in both countries.
It is now the future and a Mary has become the new Queen of the UK.
Is she "Queen Mary III", because she will succeed from Queen Mary II? or...
Is she "Queen Mary IV", because she will be the 4th Queen Mary in the combined crown of the UK?