Interview Problem Doubt

Help me to solve this:

please find attached screenshot link:

TestCase:
2 2
1 2
0 1

Answer : 3