def gas_station(gas, cost):
    if not gas:
        return -1
    total = tank = candidate = 0
    for i in range(len(gas)):
        surplus = gas[i] - cost[i]
        total += surplus
        tank += surplus
        if tank < 0:
            candidate = i + 1
            tank = 0
    return candidate if total >= 0 else -1
