Help needed to solve a interesting MEX problem

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

Any array input or each N array or what?

Array of Arrays. Each subarray size is M and the entire Big Array size is N.
int solve(vector<vector>& A, int N, int M)

N = A.size(), M = A[0].size()