```python
def time_gap(from_hour: int, from_minute: int, to_hour: int, to_minute: int)    -> int:
    # Validate input ranges
    if not (0 <= from_hour <= 23 and 0 <= from_minute <= 59 and 0 <= to_hour <= 23 and 0 <= to_minute <= 59):
        raise ValueError("Invalid hour or minute value")

    # Calculate total minutes from the start of the day
    from_total_minutes = from_hour * 60 + from_minute
    to_total_minutes = to_hour * 60 + to_minute

    # If the second time is earlier than the first, it falls on the following day
    if to_total_minutes < from_total_minutes:
        to_total_minutes += 24 * 60

    # Calculate the gap in minutes
    gap = to_total_minutes - from_total_minutes

    return gap
```