Loss function for array of integers where rank matters

My required output from a model is an integer array and the order of those integers in the array are important. As an example,

Let [10, 7, 8, 3, 2] be the expected result.

Then [10, 8, 7, 3, 2] should have a low loss while [8, 1, 5, 6, 7] should have a high loss.

Please let me know a reasonable loss function for this since I don’t think that square loss or cross entropy loss grasp the idea