```ts
export function firstOverload(bookings: number[][], capacity: number): number {
  if (capacity < 1) throw new Error("Capacity must be at least 1");
  for (const [start, end] of bookings) {
    if (!Number.isInteger(start) || !Number.isInteger(end)) throw new Error("Endpoints must be integers");
    if (start >= end) throw new Error("Booking start must come before its end");
  }

  const events: { time: number; type: 'start' | 'end' }[] = [];
  for (const [start, end] of bookings) {
    events.push({ time: start, type: 'start' });
    events.push({ time: end, type: 'end' });
  }

  events.sort((a, b) => a.time - b.time || (a.type === 'end' ? 1 : -1));

  let activeBookings = 0;
  for (const event of events) {
    if (event.type === 'start') {
      activeBookings++;
      if (activeBookings > capacity) return event.time;
    } else {
      activeBookings--;
    }
  }

  return -1;
}
```