def h_index(citations):
    """
    Calculate the H-index
    https://en.wikipedia.org/wiki/H-index
    :param citations: list of citations (sorted or unsorted)
    """

    c = list(citations)
    c.sort(reverse=True)

    for i in range(len(c)):
        if i > c[i]:
            return i

    return len(c)