def top_n_peaks(spectrum, N):
    """
    Takes the most-intense N peaks of the given scan, and discards the rest.
    """
    N = int(N) if N else 0
    return sorted(spectrum, key=lambda x: x[1], reverse=True)[:int(N)]
