# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

#
# 
# @param root TreeNode类 
# @return int整型
#
import sys
sys.setrecursionlimit(1000000)  # 提高递归深度

class Solution:
    def run(self , root ):
        # write code here
        def do_tree(cur):
            if cur is None:
                return 0
            if cur.left is None and cur.right is None:
                return 1
            if cur.left is None or cur.right is None:
                return max([do_tree(cur.left), do_tree(cur.right)]) + 1
            return min([do_tree(cur.left), do_tree(cur.right)]) + 1
        n = do_tree(root)
        return n