// Arup Guha
// 9/17/2015
// Solution to 2015 January USACO Bronze Problem: Meeting Time

import java.util.*;
import java.io.*;

public class meeting {

	final public static int NO_RESULT = 1000000;

	public static void main(String[] args) throws Exception {

		Scanner stdin = new Scanner(new File("meeting.in"));

		// Get graph size.
		int v = stdin.nextInt();
		int e = stdin.nextInt();
		int[][] bessie = new int[v][v];
		init(bessie);
		int[][] elsie = new int[v][v];
		init(elsie);

		// Read in all edges.
		for (int i=0; i<e; i++) {
			int v1 = stdin.nextInt()-1;
			int v2 = stdin.nextInt()-1;
			bessie[v1][v2] = stdin.nextInt();
			elsie[v1][v2] = stdin.nextInt();
		}

		// Calculate all possible distances for both bessie and elsie from start to finish.
		TreeSet<Integer> bessieList = getPossibleDistances(bessie);
		TreeSet<Integer> elsieList = getPossibleDistances(elsie);

		// Go through one list, looking for matches in the other.
		int res = NO_RESULT;
		for (Integer x: bessieList)
			if (elsieList.contains(x))
				res = Math.min(res, x);


		PrintWriter out = new PrintWriter(new File("meeting.out"));

		// Output result.
		if (res != NO_RESULT) 	out.println(res);
		else					out.println("IMPOSSIBLE");
		out.close();
	}

	// Graph with no edges...
	public static void init(int[][] graph) {
		for (int i=0; i<graph.length; i++) {
			Arrays.fill(graph[i], NO_RESULT);
			graph[i][i] = 0;
		}
	}

	public static TreeSet<Integer> getPossibleDistances(int[][] graph) {

		int n = graph.length;
		TreeSet[] distances = new TreeSet[n];
		for (int i=0; i<n; i++) distances[i] = new TreeSet<Integer>();
		distances[n-1].add(0);

		// i is current node we are considering.
		for (int i=n-2; i>=0; i--) {

			// Check if we can take an edge from i to j.
			for (int j=i+1; j<n; j++) {
				if (graph[i][j] != NO_RESULT) {

					// If so, we want to update i to store all possible distances from i to end, which is edge(ij) plus
					// distances from j to end.
					for (Integer x: (TreeSet<Integer>)distances[j])
						distances[i].add(x+graph[i][j]);
				}
			}
		}

		// We only care about this particular set.
		return (TreeSet<Integer>)distances[0];
	}
}