I came across this interesting coding question asked in a Online Interview Test. How to approach to solve this question. This is what I could remember

Given an array consisting of N arrays each of size M. You can perform the following task zero or more times. Choose 1 of the N arrays. Choose some non negative integer x and append it to the chosen array. Calculate the minimum no of such operations so that the MEX of the resulting array becomes equal.

1 <= N <= 10^5

1 <= M <= 10^9