```ts
/**
 * Take back entries from the end of a list toward its start, returning how many must be taken before their total reaches a target.
 * Return -1 if the whole list never reaches the target.
 *
 * @param values The array to take back from.
 * @param target The target sum.
 * @returns The number of entries to take back or -1 if not enough.
 */
export function takeBack(values: number[], target: number): number {
    let count = 0;
    let currentSum = 0;

    for (let i = values.length - 1; i >= 0; i--) {
        currentSum += values[i];
        count++;
        if (currentSum >= target) {
            return count - 1;
        }
    }

    return -1;
}
```