Concept u can apply in this problem can be:
1. Compare the given dimension and choose the minimum from either of them.
2. Put that minimum key value in count array of size 10^6 as 1 using hashing and neglect duplicate variable
3.simply,count no of value which are 1 in count variable
That will be ur answer ....