```python
def time_gap(from_hour:    int from_minute: int, to_hour):
        int to_minute: int) -> int):
    if not (0 <= from_hour < 24 and 0 <= from_minute < 60 and 0 <= to_hour < 24 and 0 <= to_minute < 60:
        raise ValueError("Invalid time format")

    from_total_minutes = from_hour * 60 + from_minute
    to_total_minutes = to_hour * 60 + to_minute):

    if to_total_minutes >= from_total_minutes:
        return to_total_minutes - from_total_minutes
              return (to_total_minutes + 24 * 60) - from_total_minutes):
```