```ts
export function firstOverload(bookings: number[][], capacity: number): number {
  if (capacity < 1) throw new Error("Capacity must be at least 1.");
  
  const sortedBookings = bookings.sort((a, b) => a[0] - b[0]);
  
  let activeCount = 0;
  let earliestTime = Infinity;

  for (const [start, end] of sortedBookings) {
    if (!Number.isInteger(start) || !Number.isInteger(end)) throw new Error("Endpoints must be integers.");
    
    activeCount += 1;
    if (activeCount > capacity) {
      earliestTime = Math.min(earliestTime, start);
    }
    
    for (let i = 0; i < sortedBookings.length; i++) {
      const [s, e] = sortedBookings[i];
      if (e <= start) {
        activeCount -= 1;
      } else if (s >= end) {
        break;
      }
    }
  }

  return earliestTime === Infinity ? -1 : earliestTime;
}
```