Dynamic programing problem

Help me to solve this question, I got into the interview, not able to solve it.
please find the link of the problem:

TestCase:
2 2
1 2
0 1
Answer: 3