```
class Solution {
public int findSecondMinimumValue(TreeNode root) {
if(root == null) return -1;
return findSecond(root, root.val);
}
private int findSecond(TreeNode root, int x) {
if (root == null) return -1;
if (root.val != x) return root.val;
else {
int left = findSecond(root.left, x);
int right = findSecond(root.right, x);
if (left == -1) return right;
else if (right == -1) return left;
else return Math.min(left, right);
}
}
}
```