int get(int key) {
        Node x = root;
        while (x != null) {
            if (key < x.key) {
                x = x.left;
            } else if (key > x.key) {
                x = x.right;
            } else {
                return x.val;
            }
        }
        return -1;
    }