def tokens2int(text, tokens, negative_sign='-'):
    """
    Convert a number to the least amount tokens (within a tokens set).

    Items in the tokens set must not repeat/overlap.

    This is the inverse of `tokens2int()` given the same tokens set.

    Args:
        text (str): The input string to parse.
        tokens (Iterable[str]): The tokens to use for the representation.
            Items within the tokens set must not repeat or overlap.
        negative_sign (str): The symbol to use for negative numbers.
            The negative sign must be the first character of the
            representation.

    Returns:
        num (int): The integer represented.

    Examples:
        >>> [tokens2int(s, ('po', 'ta')) for s in ['po', 'ta', 'popo', 'pota']]
        [0, 1, 2, 3]
        >>> tokens2int('potapopopotata', ('po', 'ta'))
        161
        >>> d = ('mo', 'no', 'ke')
        >>> all(n == tokens2int(int2tokens(n, d), d) for n in range(-99, 999))
        True

    See Also:
        letter2int(), int2letter(), int2tokens()
    """
    num = 0
    sign = 1
    text = text.strip()
    if negative_sign in tokens:
        raise ValueError('Negative sign must not be a token')
    if negative_sign in text:
        if text[0] == negative_sign:
            text = text[1:]
            sign = -1
        else:
            raise ValueError('Negative sign is in wrong position')
    if not set(text).issubset(set(''.join(tokens))):
        raise ValueError('Text contains invalid characters')
    i = 0
    found = True
    while text or not found:
        found = False
        for j, token in enumerate(tokens):
            if text.endswith(token):
                text = text[:-len(token)]
                offset = 0 if i == 0 else 1
                num += (j + offset) * len(tokens) ** i
                found = True
                i += 1
    return num * sign
