The problem is similar to LeetCode 300: Longest Increasing Subsequence and LeetCode 354: Russian Doll Envelopes . And I learnt from their solutions: LeetCode 300 Solution and LeetCode 354 Solution.

```
public int findLongestChain(int[][] pairs) {
Arrays.sort(pairs, new Comparator<int[]>(){
@Override
public int compare(int[] o1, int[] o2){
return o1[0] - o2[0];
}
});
int res = 0;
int[] dp = new int[pairs.length];
for(int[] pair: pairs){
int num1 = pair[0], num2 = pair[1];
int i = Arrays.binarySearch(dp, 0, res, num1);
if(i < 0) i = - (i + 1);
int j = Arrays.binarySearch(dp, 0, res, num2);
if(j < 0) j = - (j + 1);
dp[j] = num2;
if(i == j && j == res) res++;
}
return res;
}
```