// Arup Guha
// 7/1/2014
// Solution to 2014 World Finals Problem K: Surveillance

import java.util.*;
import java.io.*;

public class k {

	final public static int NOSOLUTION = 1000000000;
	public static int len;
	public static int n;

	public static void main(String[] args) throws Exception {

		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		len = Integer.parseInt(tok.nextToken());
		n = Integer.parseInt(tok.nextToken());

		// Read in list.
		cover[] list = new cover[n];
		for (int i=0; i<n; i++) {
			tok = new StringTokenizer(stdin.readLine());
			int s = Integer.parseInt(tok.nextToken());
			int e = Integer.parseInt(tok.nextToken());
			if (e < s) e += len;
			list[i] = new cover(s,e);
		}

		// Process to store only relevant intervals.
		list = process(list);

		// Solve and output.
		int sol = solve(list);
		if (sol < NOSOLUTION) System.out.println(sol);
		else         System.out.println("impossible");
	}

	public static int solve(cover[] list) {

		// Set up queue of intervals.
		int ans = NOSOLUTION;
		LinkedList<cover> q = new LinkedList<cover>();
		q.offer(list[0]);
		if (list[0].total() >= len-1 && list[0].size < ans) ans = list[0].size;

		for (int i=1; i<list.length; i++) {

			// We can always start a new covering here.
			q.offer(list[i]);
			if (list[i].total() >= len-1 && list[i].size < ans) ans = list[i].size;

			// These streaks die.
			while (q.peek().end < list[i].start-1) cover cur = q.poll();

			// Need to greedily build off the front of the queue.
			while (i+1 == list.length || q.peek().end < list[i+1].start-1) {
				cover cur = q.poll();
				cover next = cur.add(list[i]);

				if (next.total() >= len-1 && next.size < ans) ans = next.size;
				else if (next.end > cur.end) q.offer(next);

				if (q.size() == 0) break;
			}
		}

		return ans;

	}

	public static cover[] process(cover[] list) {

		// Sort.
		Arrays.sort(list);
		cover[] ans = new cover[n];
		int j = 0;

		// Copy relevant items only.
		for (int i=0; i<n; i++)
			if ((j == 0) || (list[i].start > ans[j-1].start && list[i].end > ans[j-1].end))
				ans[j++] = list[i];

		// Resize array.
		cover[] ret = new cover[j];
		for (int i=0; i<j; i++)
			ret[i] = ans[i];

		// Store only largest conglomerate windows that matter.
		int low = 0, high = 0;
		while (low < ret.length) {

			// Looking for perfectly adjacent windows.
			while (high+1<ret.length && ret[high+1].start == ret[high].end+1) high++;
			for (int i=low; i<high; i++) {
				ret[i].size = high-i+1;
				ret[i].end = ret[high].end;
			}
			high++;
			low = high;
		}

		return ret;
	}
}

class cover implements Comparable<cover> {

	public int start;
	public int end;
	public int size;

	public cover(int s, int e) {
		start = s;
		end = e;
		size = 1;
	}

	public cover(int s, int e, int len) {
		start = s;
		end = e;
		size = len;
	}

	public int compareTo(cover other) {
		if (this.start != other.start) return this.start - other.start;
		return other.end - this.end;
	}

	public cover add(cover other) {
		return new cover(start, other.end, size+other.size);
	}

	public int total() {
		return end-start;
	}

	public String toString() {
		return start+"-"+end+": "+size;
	}
}