def perm_compose_i(p1, p2, n=None):
    """
    Returns the product `p1^{-1} p2^{-1}`.

    EXAMPLES::

        sage: from surface_dynamics.misc.permutation import perm_compose_i
        sage: perm_compose_i([0,1,2],[1,2,0])
        [2, 0, 1]

        sage: from surface_dynamics.misc.permutation import perm_invert, perm_compose
        sage: from itertools import permutations
        sage: for p1 in permutations(range(4)):
        ....:     for p2 in permutations(range(4)):
        ....:         assert perm_compose_i(p1, p2) == perm_compose(perm_invert(p1), perm_invert(p2))
    """
    if n is None:
        n = len(p1)
    res = [-1] * n
    for i in range(len(p1)):
        if p2[i] != -1 and p1[p2[i]] != -1:
            res[p1[p2[i]]] = i
    return res
