Given an integer array, find the minimum number of operations to make all numbers equal by reversing any digit.
In one operation, choose a distinct value and reverse the digits of every occurrence of that value. Return the minimum operations, or -1 if no common target is reachable. For example, [10, 1, 10] returns 1, because reversing the value 10 changes both occurrences to 1.
Input: a nonempty list nums of nonnegative integers. Output: an integer.
Examples: [12, 21, 12] returns 1; [7, 7, 7] returns 0.
Constraints: 1 <= len(nums) <= 1000, and 0 <= nums[i] <= 10^9.
def min_operations(nums):