def decode_modm(limbs):
    """
    Decodes scalar mod m from limbs with base 30
    :param n:
    :return:
    """
    n = 0
    c = 0
    shift = 0
    mask = (1 << 30) - 1
    for i in range(9):
        n += (limbs[i] & mask) + c << shift
        c = limbs[i] >> 30
        shift += 30
    return n
