from heapq import heappop, heappush


def sssp(graph: list[list[tuple[int, int]]], s: int) -> list[int]:
    """
    Computes the single source shortest paths (SSSP) from vertex s.
    :param graph: The graph as an adjacency list.
    graph[u] contains the adjacency list to vertex u.
    Each element of the adjacency list is a pair of [v, w] where v is the vertex and w is the edge weight.
    :param s: The source vertex.
    :return: An array of distances from the source vertex to every vertex in the graph.
    """
    N = len(graph)
    dist = [float("inf")] * N
    dist[s] = 0
    pq = [(0, s)]
    while pq:
        d, u = heappop(pq)
        if d > dist[u]:
            continue
        for v, w in graph[u]:
            if d + w < dist[v]:
                dist[v] = d + w
                heappush(pq, (d + w, v))
    return dist


if __name__ == "__main__":
    """
    Taking input.
    N: Number of islands.
    M: Number of bridges.
    T: Number of minutes in a day. This is equal to 1440.
    Every bridge is described by 5 integers u, v, w, s, e.
    The bridge goes from vertex u to v and takes w minutes to traverse.
    The bridge is only open between minute s and e each day.
    It is guaranteed that s + w <= e.
    """
    N, M = map(int, input().split())
    T = 1440
    graph = [[] for _ in range(N)]
    for i in range(M):
        u, v, w, s, r = map(int, input().split())
        graph[u].append((v, w, s, r))
    # for any vertex u
    # graph[u] contains a list of all out-neighbors 
    # and the respective w,s,r values
    
    """
    START OF YOUR CODE
    """
    answer = 0
    # TODO write code here.
    """
    END OF YOUR CODE
    """

    """
    Printing output.
    """
    print(answer)
