import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class VK673 {
	public static void main(String[] args) {
//		bearAndGame(System.in);
//		problemsForRound(System.in);
//		bearAndColors(System.in);
//		testBearAndColors();
		bearAndTwoPaths(System.in);
	}

	public static void bearAndTwoPaths(InputStream in) {
		MyScanner scan = new MyScanner(in);
		int n = scan.nextInt();
		int k = scan.nextInt();

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();

		ArrayList<Integer> open = new ArrayList<>();
		HashSet<Integer> closed = new HashSet<>();
		closed.add(a);
		closed.add(b);
		closed.add(c);
		closed.add(d);
		for (int i = 1; i <= n; i++) {
			if (!closed.contains(i)) {
				open.add(i);
			}
		}

		if (n > 4) {
			if (k < n + 1) {
				System.out.println("-1");
			} else {
				System.out.print(a + " " + c + " ");
				for (int i = 0; i < open.size(); i++) {
					System.out.print(open.get(i) + " ");
				}
				System.out.println(d + " " + b);

				System.out.print(c + " " + a + " ");
				for (int i = 0; i < open.size(); i++) {
					System.out.print(open.get(i) + " ");
				}
				System.out.println(b + " " + d);
			}
		} else {
			System.out.println("-1");
		}
	}

	public static void testBearAndColors() {
		Random rand = new Random(0);
		for (int i = 0; i < 10000; i++) {
			for (int len = 1; len < 10; len++) {
				for (int numCol = 1; numCol <= len; numCol++) {
					int[] a = new int[len];
					for (int j = 0; j < a.length; j++) {
						a[j] = rand.nextInt(numCol);
					}

					int[] numDom = new int[a.length+1];
					for (int y = 0; y < a.length; y++) {
						for (int x = y; x < a.length; x++) {
							int[] fcount = new int[a.length+1];
							for (int j = y; j <= x; j++) {
								fcount[a[j]]++;
							}
							int max = 0;
							int maxN = a.length + 10;
							for (int j = 0; j < fcount.length; j++) {
								if (fcount[j] > max || (max == fcount[j] && j < maxN)) {
									max = fcount[j];
									maxN = j;
								}
							}
							numDom[maxN+1]++;
						}
					}

					for (int j = 0; j < a.length; j++) {
						a[j]++;
					}

					int[] nd2 = bearAndColors(a);
					if (!Arrays.equals(numDom, nd2)) {
						System.out.println("fail");
					}
				}
			}
		}
	}

	public static void bearAndColors(InputStream in) {
		MyScanner scan = new MyScanner(in);
		int n = scan.nextInt();
		int[] t = scan.nextIntArray(n);
		int[] numDom = bearAndColors(t);

		StringBuilder out = new StringBuilder();
		for (int i = 1; i < numDom.length; i++) {
			if (i > 1) {
				out.append(" ");
			}
			out.append(numDom[i]);
		}
		System.out.println(out);
	}

	private static int[] bearAndColors(int[] t) {
		int[] numDom = new int[t.length+1];
		for (int y = 0; y < t.length; y++) {
			HashMap<Integer, Integer> map = new HashMap<>();
			int max = 0;
			int maxN = 0;
			for (int x = y; x < t.length; x++) {
				if (x == y) {
					max = 1;
					maxN = t[x];
					map.put(t[x], 1);
					numDom[maxN]++;
				} else {
					if (!map.containsKey(t[x])) {
						map.put(t[x], 1);
					} else {
						map.put(t[x], map.get(t[x]) + 1);
					}
					int currentF = map.get(t[x]);
					if (currentF > max || (currentF == max && t[x] < maxN)) {
						max = currentF;
						maxN = t[x];
					}
					numDom[maxN]++;
				}
			}
		}
		return numDom;
	}

	public static void problemsForRound(InputStream in) {
		MyScanner scan = new MyScanner(in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] d1 =  new int[m];
		int[] d2 =  new int[m];

		int max1 = 1;
		int min2 = n;
		for (int i = 0; i < m; i++) {
			int[] a = scan.nextIntArray(2);
			Arrays.sort(a);
			d1[i] = a[0];
			d2[i] = a[1];
			max1 = Math.max(max1, d1[i]);
			min2 = Math.min(min2, d2[i]);
		}

		if (max1 >= min2) {
			System.out.println(0);
		} else {
			System.out.println(min2 - max1);
		}
	}

	public static void bearAndGame(InputStream in) {
		MyScanner scan = new MyScanner(in);
		int n = scan.nextInt();
		int[] x = scan.nextIntArray(n);
		boolean[] watch = new boolean[90];
		int i = 0;
		for (int j = 0; j < 15; j++) {
			if (i+j < watch.length) {
				watch[i+j] = true;
			}
		}
		for (i = 0; i < x.length; i++) {
			for (int j = 0; j < 15; j++) {
				if (x[i]+j < watch.length) {
					watch[x[i]+j] = true;
				}
			}
		}
		int stop = 90;
		for (i = 0; i < watch.length; i++) {
			if (!watch[i]) {
				stop = i;
				break;
			}
		}
		System.out.println(stop);
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner(InputStream in) {
			this.br = new BufferedReader(new InputStreamReader(in));
		}

		public void close() {
			try {
				this.br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					String s = br.readLine();
					if (s != null) {
						st = new StringTokenizer(s);
					} else {
						return null;
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < a.length; i++) {
				a[i] = this.nextLong();
			}
			return a;
		}

		int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < a.length; i++) {
				a[i] = this.nextInt();
			}
			return a;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine(){
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


import java.io.*;
import java.util.*;

public class D{
    static java.io.PrintStream out=System.out;
    void solve(int n, int k, int[] t){
        if(n<=4 || k<=n){
            out.println(-1);
            return;
        }
        Set<Integer> set=new HashSet<>();
        set.add(t[1]);
        set.add(t[2]);
        set.add(t[4]);
        set.add(t[n]);
        int i=1;
        while(set.contains(i)) i++;
        t[3]=i;
        for(int j=5; j<n; j++){
            i++;
            while(set.contains(i)) i++;
            t[j]=i;
        }
        for(i=1; i<=n; i++)
            out.print(t[i]+" ");
        out.println();
        out.print(t[2]+" ");
        out.print(t[1]+" ");
        out.print(t[3]+" ");
        for(i=n; i>3; i--)
            out.print(t[i]+" ");
        out.println();
    }
    public static void main(String[] argin) {
        D inst = new D();
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int n = in.nextInt(), k=in.nextInt();
            int[] t = new int[n+1];
            t[1]=in.nextInt();
            t[n]=in.nextInt();
            t[2]=in.nextInt();
            t[4]=in.nextInt();
            inst.solve(n,k,t);
        }
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

/**
 * Created by Alexandr on 19.11.2016.
 */
public class mark {

    public void solve() throws IOException {
        int n = nextInt ();
        int m = nextInt ();
        int a[] = new int[n];
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < m; i++){
            int l = nextInt ();
            int r = nextInt ();
            min = Math.min (min, r - l + 1);
        }
        out.println (min);
        for(int i = 0; i < n; i++){
            out.print ((i % min) + " ");
        }
    }

    BufferedReader br;
    StringTokenizer sc;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens ()) {
            try {
                sc = new StringTokenizer (br.readLine ());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken ();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt (nextToken ());
    }

    public boolean hasNext() {
        while (sc == null || !sc.hasMoreTokens ()) {
            try {
                String s = br.readLine ();
                if (s == null) {
                    return false;
                }
                sc = new StringTokenizer (s);
            } catch (IOException e) {
                throw new RuntimeException (e);
            }
        }
        return sc.hasMoreTokens ();
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble (nextToken ());
    }

    public long nextLong() throws IOException {
        return Long.parseLong (nextToken ());
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault (Locale.US);
        new mark ().run ();
    }

    public void run() {
        try {
            br = new BufferedReader (new InputStreamReader (System.in));
            out = new PrintWriter (System.out);
//            br = new BufferedReader (new FileReader ("billboard.in"));
//            out = new PrintWriter (new File ("billboard.out"));
            solve ();
            out.close ();
        } catch (IOException e) {
            e.printStackTrace ();
            System.exit (1);
        }
    }
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main extends Reader {

	public static void main(String[] args) throws IOException {
	    int n = ni(), m = ni(), len = n;
	    for (int i=0; i<m; i++) {
	        int l = ni(), r = ni();
	        len = Math.min(len, r-l+1);
	    }
	    System.out.println(len);
	    for (int i=0; i<n; i++) {
	        System.out.printf("%d ", i % len);
	    }
	}
}

class Reader {
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tokenizer = new StringTokenizer("");

    /** call this method to change InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(new InputStreamReader(input) );
    }

    /** get next word */
    static String ns() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int ni() throws IOException {
        return Integer.parseInt( ns() );
    }

    static double nd() throws IOException {
        return Double.parseDouble( ns() );
    }
    static long nl() throws IOException {
        return Long.valueOf( ns() );
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class Alyona_and_mex2 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();

		ArrayList <Long> arr = new ArrayList();   /* ********* ArrayList ************* */
		StringBuilder output = new StringBuilder();

		long m =sc.nextLong();
		long min = 0;
		long temp = 0;

		for(long i = 0; i < m; i++) {
			if (i == 0) {
				long l = sc.nextLong();
				long r = sc.nextLong();
				min = r - l;

			} else {
				long l = sc.nextLong();
				long r = sc.nextLong();
				temp = r - l;
				if (temp < min) {
					min = temp;
				}
			}
		}
		long maxMex = min + 1;
		System.out.println(maxMex);

		long counter = 0;
		for (long i = 0; i < n; i++) {
			if (i == n - 1) {
				if (counter < maxMex) {
					output.append(counter);
					counter++;
				} else {
					counter = 0;
					output.append(counter);
					counter++;
				}
			} else {
				if (counter < maxMex) {
					output.append(counter);
					output.append(" ");
					counter++;
				} else {
					counter = 0;
					output.append(counter);
					output.append(" ");
					counter++;
				}
			}

		}

		System.out.println(output);

	}

}


import java.util.ArrayList;
import java.util.Scanner;

public class Alyona_and_mex2 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();

		ArrayList <Long> arr = new ArrayList();   /* ********* ArrayList ************* */
		StringBuilder output = new StringBuilder();

		long m =sc.nextLong();
		long min = 0;
		long temp = 0;

		for(long i = 0; i < m; i++) {
			if (i == 0) {
				long l = sc.nextLong();
				long r = sc.nextLong();
				min = r - l;

			} else {
				long l = sc.nextLong();
				long r = sc.nextLong();
				temp = r - l;
				if (temp < min) {
					min = temp;
				}
			}
		}
		long maxMex = min + 1;
		System.out.println(maxMex);

		long counter = 0;
		for (long i = 0; i < n; i++) {
			if (counter < maxMex) {
				output.append(counter);
				counter++;
			} else {
				counter = 0;
				output.append(counter);
				counter++;
			}
		}
		System.out.println(output);

	}

}


import javax.swing.text.Segment;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main implements Runnable {
	static final double time = 1e9;
	static final int MOD = (int) 1e9 + 7;
	static final long mh = Long.MAX_VALUE;
	static final Reader in = new Reader();
	static final PrintWriter out = new PrintWriter(System.out);
	StringBuilder answer = new StringBuilder();
	long start = System.nanoTime();

	public static void main(String[] args) {
		new Thread(null, new Main(), "persefone", 1 << 28).start();
	}

	@Override
	public void run() {

		solve();
		printf();
		long elapsed = System.nanoTime() - start;
//		out.println("stamp : " + elapsed / time);
//		out.println("stamp : " + TimeUnit.SECONDS.convert(elapsed, TimeUnit.NANOSECONDS));
		close();
//		out.flush();
	}

	void solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		int min = n;
		for (int i = 0; i < m; i++) min = Math.min(min, -in.nextInt() + in.nextInt() + 1);

		List<Integer> ans = new ArrayList<>();
		for (int i = 0; i < n / min; i++) for (int j = 0; j < min; j++) ans.add(j);
		for (int i = 0; i < n % min; i++) ans.add(i);
		printf(ans);
	}

	static class Fenwick {
		private int n;
		private int[] count;
		public Fenwick(int n) {
			this.n = 2 * n + 10;
			count = new int[this.n];
		}

		void update(int i, int val) {
			for (; i < n; i += i & -i) count[i] += val;
		}

		int get(int i) {
			int sum = 0;
			for (; i > 0; i -= i & -i) sum += count[i];
			return sum;
		}

		int getRange(int i, int j) { return  get(j) - get(i); }
	}

	static class ArrayUtils {
		static void compressed(int[] a, int n) {
			int[] b = a.clone();
			Arrays.sort(b);
			for (int i = 0; i < n; i++) a[i] = lw(b, 0, n, a[i]) + 1;
		}

		static  int lw(int[] b, int l, int r, int k) {
			int R = r, m = 0;
			while (l <= r) {
				m = l + r >> 1;
				if (m == R) return m;
				if (b[m] >= k) r = m - 1;
				else l = m + 1;
			}
			return l;
		}
	}

	void printf() {
		out.print(answer);
	}

	void close() {
		out.close();
	}

	void printf(Stream<?> str) {
		str.forEach(o -> add(o, " "));
		add("\n");
	}

	void printf(Object... obj) {
		printf(false, obj);
	}

	void printfWithDescription(Object... obj) {
		printf(true, obj);
	}

	private void printf(boolean b, Object... obj) {

		if (obj.length > 1) {
			for (int i = 0; i < obj.length; i++) {
				if (b) add(obj[i].getClass().getSimpleName(), " - ");
				if (obj[i] instanceof Collection<?>) {
					printf((Collection<?>) obj[i]);
				} else if (obj[i] instanceof int[][]) {
					printf((int[][])obj[i]);
				} else if (obj[i] instanceof long[][]) {
					printf((long[][])obj[i]);
				} else if (obj[i] instanceof double[][]) {
					printf((double[][])obj[i]);
				} else printf(obj[i]);
			}
			return;
		}

		if (b) add(obj[0].getClass().getSimpleName(), " - ");
		printf(obj[0]);
	}

	void printf(Object o) {
		if (o instanceof int[])
			printf(Arrays.stream((int[]) o).boxed());
		else if (o instanceof char[])
			printf(new String((char[]) o));
		else if (o instanceof long[])
			printf(Arrays.stream((long[]) o).boxed());
		else if (o instanceof double[])
			printf(Arrays.stream((double[]) o).boxed());
		else if (o instanceof boolean[]) {
			for (boolean b : (boolean[]) o) add(b, " ");
			add("\n");
		}
		else
			add(o, "\n");
	}

	void printf(int[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(long[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(double[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(boolean[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(Collection<?> col) {
		printf(col.stream());
	}

	<T, K> void add(T t, K k) {
		if (t instanceof Collection<?>) {
			((Collection<?>) t).forEach(i -> add(i, " "));
		} else if (t instanceof Object[]) {
			Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
		} else
			add(t);
		add(k);
	}

	<T> void add(T t) {
		answer.append(t);
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T min(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) < 0)
				m = t[i];
		return m;
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T max(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) > 0)
				m = t[i];
		return m;
	}

	int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	// c = gcd(a, b) -> extends gcd method: ax + by = c <----> (b % a)p + q = c;
	int[] ext_gcd(int a, int b) {
		if (b == 0) return new int[] {a, 1, 0 };
		int[] vals = ext_gcd(b, a % b);
		int d = vals[0]; // gcd
	    int p = vals[2]; //
		int q = vals[1] - (a / b) * vals[2];
		return new int[] { d, p, q };
	}

	// find any solution of the equation: ax + by = c using extends gcd
	boolean find_any_solution(int a, int b, int c, int[] root) {
		int[] vals = ext_gcd(Math.abs(a), Math.abs(b));
		if (c % vals[0] != 0) return false;
		printf(vals);
		root[0] = c * vals[1] / vals[0];
		root[1] = c * vals[2] / vals[0];
		if (a < 0) root[0] *= -1;
		if (b < 0) root[1] *= -1;
		return true;
	}

	int mod(int x) { return x % MOD; }

	int mod(int x, int y) { return mod(mod(x) + mod(y)); }

	long mod(long x) { return x % MOD; }

	long mod (long x, long y) { return mod(mod(x) + mod(y)); }

	int lw(long[] f, int l, int r, long k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] >= k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int up(long[] f, int l, int r, long k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] > k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int lw(int[] f, int l, int r, int k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] >= k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int up(int[] f, int l, int r, int k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] > k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	<K extends Comparable<K>> int lw(List<K> li, int l, int r, K k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (li.get(m).compareTo(k) >= 0)
		    	r = m - 1;
		    else
		    	l = m + 1;
		}
		return l;
	}

	<K extends Comparable<K>> int up(List<K> li, int l, int r, K k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (li.get(m).compareTo(k) > 0)
		    	r = m - 1;
		    else
		    	l = m + 1;
		}
		return l;
	}

	<K extends Comparable<K>> int bs(List<K> li, int l, int r, K k) {
		while (l <= r) {
			int m = l + r >> 1;
		    if (li.get(m) == k) return m;
		    else if (li.get(m).compareTo(k) < 0)
		    	l = m + 1;
		    else
		    	r = m - 1;
		}
		return -1;
	}

	long calc(int base, int exponent) {
		if (exponent == 0) return 1;
		if (exponent == 1) return base % MOD;
		long m = calc(base, exponent / 2);
		if (exponent % 2 == 0) return (m * m) % MOD;
		return (base * ((m * m) % MOD)) % MOD;
	}

	long calc(int base, long exponent) {
		if (exponent == 0) return 1;
		if (exponent == 1) return base % MOD;
		long m = calc(base, exponent / 2);
		if (exponent % 2 == 0) return (m * m) % MOD;
		return (base * ((m * m) % MOD)) % MOD;
	}

	long calc(long base, long exponent) {
		if (exponent == 0) return 1;
		if (exponent == 1) return base % MOD;
		long m = calc(base, exponent / 2);
		if (exponent % 2 == 0) return (m * m) % MOD;
		return (base * (m * m % MOD)) % MOD;
	}

	long power(int base, int exponent) {
		if (exponent == 0) return 1;
		long m = power(base, exponent / 2);
		if (exponent % 2 == 0) return m * m;
		return base * m * m;
	}

	void swap(int[] a, int i, int j) {
		a[i] ^= a[j];
		a[j] ^= a[i];
		a[i] ^= a[j];
	}

	void swap(long[] a, int i, int j) {
		long tmp = a[i];
		a[i] = a[j];
		a[j] = tmp;
	}

	static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
			implements Comparable<Pair<K, V>> {
		private K k;
		private V v;

		Pair() {}

		Pair(K k, V v) {
			this.k = k;
			this.v = v;
		}

		K getK() { return k; }

		V getV() { return v; }

		void setK(K k) { this.k = k; }

		void setV(V v) { this.v = v; }

		void setKV(K k, V v) {
			this.k = k;
			this.v = v;
		}

		@SuppressWarnings("unchecked")
		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof Pair)) return false;
			Pair<K, V> p = (Pair<K, V>) o;
			return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
		}

		@Override
		public int hashCode() {
			int hash = 31;
			hash = hash * 89 + k.hashCode();
			hash = hash * 89 + v.hashCode();
			return hash;
		}

		@Override
		public int compareTo(Pair<K, V> pair) {
			return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
		}

		@Override
		public Pair<K, V> clone() {
			return new Pair<K, V>(this.k, this.v);
		}

		@Override
		public String toString() {
			return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
		}
	}

	static class Reader {
		private BufferedReader br;
		private StringTokenizer st;

		Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			try {
				while (st == null || !st.hasMoreTokens()) {
					st = new StringTokenizer(br.readLine());
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++)
				arr[i] = nextInt();
			return arr;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String s = "";
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;
		}
	}
}


import javax.swing.text.Segment;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main implements Runnable {
	static final double time = 1e9;
	static final int MOD = (int) 1e9 + 7;
	static final long mh = Long.MAX_VALUE;
	static final Reader in = new Reader();
	static final PrintWriter out = new PrintWriter(System.out);
	StringBuilder answer = new StringBuilder();
	long start = System.nanoTime();

	public static void main(String[] args) {
		new Thread(null, new Main(), "persefone", 1 << 28).start();
	}

	@Override
	public void run() {

		solve();
		printf();
		long elapsed = System.nanoTime() - start;
//		out.println("stamp : " + elapsed / time);
//		out.println("stamp : " + TimeUnit.SECONDS.convert(elapsed, TimeUnit.NANOSECONDS));
		close();
//		out.flush();
	}

	void solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		int min = n;
		for (int i = 0; i < m; i++) min = Math.min(min, -in.nextInt() + in.nextInt() + 1);

		printf(min);
		List<Integer> ans = new ArrayList<>();
		for (int i = 0; i < n / min; i++) for (int j = 0; j < min; j++) ans.add(j);
		for (int i = 0; i < n % min; i++) ans.add(i);
		printf(ans);
	}

	static class Fenwick {
		private int n;
		private int[] count;
		public Fenwick(int n) {
			this.n = 2 * n + 10;
			count = new int[this.n];
		}

		void update(int i, int val) {
			for (; i < n; i += i & -i) count[i] += val;
		}

		int get(int i) {
			int sum = 0;
			for (; i > 0; i -= i & -i) sum += count[i];
			return sum;
		}

		int getRange(int i, int j) { return  get(j) - get(i); }
	}

	static class ArrayUtils {
		static void compressed(int[] a, int n) {
			int[] b = a.clone();
			Arrays.sort(b);
			for (int i = 0; i < n; i++) a[i] = lw(b, 0, n, a[i]) + 1;
		}

		static  int lw(int[] b, int l, int r, int k) {
			int R = r, m = 0;
			while (l <= r) {
				m = l + r >> 1;
				if (m == R) return m;
				if (b[m] >= k) r = m - 1;
				else l = m + 1;
			}
			return l;
		}
	}

	void printf() {
		out.print(answer);
	}

	void close() {
		out.close();
	}

	void printf(Stream<?> str) {
		str.forEach(o -> add(o, " "));
		add("\n");
	}

	void printf(Object... obj) {
		printf(false, obj);
	}

	void printfWithDescription(Object... obj) {
		printf(true, obj);
	}

	private void printf(boolean b, Object... obj) {

		if (obj.length > 1) {
			for (int i = 0; i < obj.length; i++) {
				if (b) add(obj[i].getClass().getSimpleName(), " - ");
				if (obj[i] instanceof Collection<?>) {
					printf((Collection<?>) obj[i]);
				} else if (obj[i] instanceof int[][]) {
					printf((int[][])obj[i]);
				} else if (obj[i] instanceof long[][]) {
					printf((long[][])obj[i]);
				} else if (obj[i] instanceof double[][]) {
					printf((double[][])obj[i]);
				} else printf(obj[i]);
			}
			return;
		}

		if (b) add(obj[0].getClass().getSimpleName(), " - ");
		printf(obj[0]);
	}

	void printf(Object o) {
		if (o instanceof int[])
			printf(Arrays.stream((int[]) o).boxed());
		else if (o instanceof char[])
			printf(new String((char[]) o));
		else if (o instanceof long[])
			printf(Arrays.stream((long[]) o).boxed());
		else if (o instanceof double[])
			printf(Arrays.stream((double[]) o).boxed());
		else if (o instanceof boolean[]) {
			for (boolean b : (boolean[]) o) add(b, " ");
			add("\n");
		}
		else
			add(o, "\n");
	}

	void printf(int[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(long[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(double[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(boolean[]... obj) {
		for (int i = 0; i < obj.length; i++) printf(obj[i]);
	}

	void printf(Collection<?> col) {
		printf(col.stream());
	}

	<T, K> void add(T t, K k) {
		if (t instanceof Collection<?>) {
			((Collection<?>) t).forEach(i -> add(i, " "));
		} else if (t instanceof Object[]) {
			Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
		} else
			add(t);
		add(k);
	}

	<T> void add(T t) {
		answer.append(t);
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T min(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) < 0)
				m = t[i];
		return m;
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T max(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) > 0)
				m = t[i];
		return m;
	}

	int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	// c = gcd(a, b) -> extends gcd method: ax + by = c <----> (b % a)p + q = c;
	int[] ext_gcd(int a, int b) {
		if (b == 0) return new int[] {a, 1, 0 };
		int[] vals = ext_gcd(b, a % b);
		int d = vals[0]; // gcd
	    int p = vals[2]; //
		int q = vals[1] - (a / b) * vals[2];
		return new int[] { d, p, q };
	}

	// find any solution of the equation: ax + by = c using extends gcd
	boolean find_any_solution(int a, int b, int c, int[] root) {
		int[] vals = ext_gcd(Math.abs(a), Math.abs(b));
		if (c % vals[0] != 0) return false;
		printf(vals);
		root[0] = c * vals[1] / vals[0];
		root[1] = c * vals[2] / vals[0];
		if (a < 0) root[0] *= -1;
		if (b < 0) root[1] *= -1;
		return true;
	}

	int mod(int x) { return x % MOD; }

	int mod(int x, int y) { return mod(mod(x) + mod(y)); }

	long mod(long x) { return x % MOD; }

	long mod (long x, long y) { return mod(mod(x) + mod(y)); }

	int lw(long[] f, int l, int r, long k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] >= k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int up(long[] f, int l, int r, long k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] > k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int lw(int[] f, int l, int r, int k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] >= k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	int up(int[] f, int l, int r, int k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (f[m] > k) r = m - 1; else l = m + 1;
		}
		return l;
	}

	<K extends Comparable<K>> int lw(List<K> li, int l, int r, K k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (li.get(m).compareTo(k) >= 0)
		    	r = m - 1;
		    else
		    	l = m + 1;
		}
		return l;
	}

	<K extends Comparable<K>> int up(List<K> li, int l, int r, K k) {
		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
		    if (m == R) return m;
		    if (li.get(m).compareTo(k) > 0)
		    	r = m - 1;
		    else
		    	l = m + 1;
		}
		return l;
	}

	<K extends Comparable<K>> int bs(List<K> li, int l, int r, K k) {
		while (l <= r) {
			int m = l + r >> 1;
		    if (li.get(m) == k) return m;
		    else if (li.get(m).compareTo(k) < 0)
		    	l = m + 1;
		    else
		    	r = m - 1;
		}
		return -1;
	}

	long calc(int base, int exponent) {
		if (exponent == 0) return 1;
		if (exponent == 1) return base % MOD;
		long m = calc(base, exponent / 2);
		if (exponent % 2 == 0) return (m * m) % MOD;
		return (base * ((m * m) % MOD)) % MOD;
	}

	long calc(int base, long exponent) {
		if (exponent == 0) return 1;
		if (exponent == 1) return base % MOD;
		long m = calc(base, exponent / 2);
		if (exponent % 2 == 0) return (m * m) % MOD;
		return (base * ((m * m) % MOD)) % MOD;
	}

	long calc(long base, long exponent) {
		if (exponent == 0) return 1;
		if (exponent == 1) return base % MOD;
		long m = calc(base, exponent / 2);
		if (exponent % 2 == 0) return (m * m) % MOD;
		return (base * (m * m % MOD)) % MOD;
	}

	long power(int base, int exponent) {
		if (exponent == 0) return 1;
		long m = power(base, exponent / 2);
		if (exponent % 2 == 0) return m * m;
		return base * m * m;
	}

	void swap(int[] a, int i, int j) {
		a[i] ^= a[j];
		a[j] ^= a[i];
		a[i] ^= a[j];
	}

	void swap(long[] a, int i, int j) {
		long tmp = a[i];
		a[i] = a[j];
		a[j] = tmp;
	}

	static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
			implements Comparable<Pair<K, V>> {
		private K k;
		private V v;

		Pair() {}

		Pair(K k, V v) {
			this.k = k;
			this.v = v;
		}

		K getK() { return k; }

		V getV() { return v; }

		void setK(K k) { this.k = k; }

		void setV(V v) { this.v = v; }

		void setKV(K k, V v) {
			this.k = k;
			this.v = v;
		}

		@SuppressWarnings("unchecked")
		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof Pair)) return false;
			Pair<K, V> p = (Pair<K, V>) o;
			return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
		}

		@Override
		public int hashCode() {
			int hash = 31;
			hash = hash * 89 + k.hashCode();
			hash = hash * 89 + v.hashCode();
			return hash;
		}

		@Override
		public int compareTo(Pair<K, V> pair) {
			return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
		}

		@Override
		public Pair<K, V> clone() {
			return new Pair<K, V>(this.k, this.v);
		}

		@Override
		public String toString() {
			return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
		}
	}

	static class Reader {
		private BufferedReader br;
		private StringTokenizer st;

		Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			try {
				while (st == null || !st.hasMoreTokens()) {
					st = new StringTokenizer(br.readLine());
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++)
				arr[i] = nextInt();
			return arr;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String s = "";
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;
		}
	}
}


import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main {
	public static void main(String[] args) throws Exception {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		int[] dx = { 1, 0, -1, 0, -1, -1, 1, 1 },
			  dy = { 0, 1, 0, -1, -1, 1 - 1, 1 };
		int MAX = (int) (1e5+10);

		// GCD && LCM
		long gcd(long a, long b) {
			return b == 0 ? a : gcd(b, a % b);
		}

		long lcm(long a, long b) {
			return a * (b / gcd(a, b));
		}

		// REverse a String
		String rev(String s) {
			return new StringBuilder(s).reverse().toString();
		}

		/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLUTION IS RIGHT HERE^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

		public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
			int n = in.nextInt(),m = in.nextInt();
			int[] l = new int[m] , r = new int[m];
			int min = Integer.MAX_VALUE;
			for(int i = 0; i < m; i++){
				l[i] = in.nextInt();
				r[i] = in.nextInt();
				if(r[i]-l[i]< min)
					min = r[i]-l[i];
			}
			out.println(min+1);
			int[] res = new int[n];
			fill(res,-1);
			for(int i = 0; i < m; i++){
				if(min == r[i]-l[i])
				for(int j = l[i]-1; j < r[i]; j++){
					if(res[j] == -1){
						res[j] = j-l[i]+1;
					}
				}
			}
			for(int i = 0; i < m; i++){
				//if(min == r[i]-l[i])
				for(int j = l[i]-1; j < r[i]; j++){
					if(res[j] == -1){
						res[j] = j-l[i]+1;
					}
				}
			}
			for(int i = 0; i < n; i++){
				if(res[i] == -1)
					res[i] = 0;
				out.print(res[i]+" ");
			}
		}
	}

	// pair class
	static class pair implements Comparable<pair> {
		int first, second;

		public pair() {
			this.first = 0;
			this.second = 0;
		}

		public pair(int f, int s) {
			this.first = f;
			this.second = s;
		}

		@Override
		public int compareTo(pair one) {
			if (this.first < one.first)
				return -1;
			if (this.first > one.first)
				return 1;
			if (this.second < one.second)
				return -1;
			if (this.second > one.second)
				return 1;
			return 0;
		}

	}

	/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`````````````````````````^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
	static class InputReader {
		private byte[] buf = new byte[8000];
		private int index;
		private int total;
		private InputStream in;
		// BufferedReader br = new BufferedReader(new
		// InputStreamReader(System.in));

		public InputReader(InputStream stream) {
			in = stream;
		}

		public int scan() {
			if (total == -1)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanlong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		private int scanInt() {
			int integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scandouble() {
			double doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		private float scanfloat() {
			float doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		public String scanstring() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public String scan_nextLine() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(n);
				n = scan();
			} while (!isEndOfLine(n));
			return res.toString();
		}

		public boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
		/// Input module

		public int nextInt() {
			return scanInt();
		}

		public long nextLong() {
			return scanlong();
		}

		public double nextDouble() {
			return scandouble();
		}

		public float nextFloat() {
			return scanfloat();
		}

		public String next() {
			return scanstring();
		}

		public String nextLine() throws IOException {
			return scan_nextLine();
		}

		public int[] readintArray(int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}

		public Integer[] readIntegerArray(int size) {
			Integer[] array = new Integer[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}
	}

}


import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main {
	public static void main(String[] args) throws Exception {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		int[] dx = { 1, 0, -1, 0, -1, -1, 1, 1 },
			  dy = { 0, 1, 0, -1, -1, 1 - 1, 1 };
		int MAX = (int) (1e5+10);

		// GCD && LCM
		long gcd(long a, long b) {
			return b == 0 ? a : gcd(b, a % b);
		}

		long lcm(long a, long b) {
			return a * (b / gcd(a, b));
		}

		// REverse a String
		String rev(String s) {
			return new StringBuilder(s).reverse().toString();
		}

		/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLUTION IS RIGHT HERE^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

		public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
			int n = in.nextInt(),m = in.nextInt();
			int[] l = new int[m] , r = new int[m];
			pair[] pair = new pair[m];
			int min = Integer.MAX_VALUE;
			for(int i = 0; i < m; i++){
				l[i] = in.nextInt();
				r[i] = in.nextInt();
				pair[i] = new pair(l[i],r[i]);
				if(r[i]-l[i]< min)
					min = r[i]-l[i];
			}
			out.println(min+1);
			int[] res = new int[n];
			sort(pair);
			fill(res,-1);
			for(int i = 0; i < m; i++){
				//out.println(pair[i].first+" "+pair[i].second+" qq");
				if(min == pair[i].second-pair[i].first){
					//out.println(min+" "+l[i]+" "+r[i]);
				for(int j = pair[i].first-1,k=0; j < pair[i].second; j++){
					if(res[j] == -1){
						//out.println((j+1)+" b");
						res[j] = k++;
					}else if(k == res[j])
						k++;
				}
				}
			}
			for(int i = 0; i < m; i++){
				//if(min == r[i]-l[i])
				for(int j = pair[i].first-1,k=0; j < pair[i].second; j++){
					//out.println(l[i]+" "+r[i]);
					if(res[j] == -1){
						res[j] = k++;
					}
				}
			}
			for(int i = 0; i < n; i++){
				if(res[i] == -1)
					res[i] = 0;
				out.print(res[i]+" ");
			}
		}
	}

	// pair class
	static class pair implements Comparable<pair> {
		int first, second;

		public pair() {
			this.first = 0;
			this.second = 0;
		}

		public pair(int f, int s) {
			this.first = f;
			this.second = s;
		}

		@Override
		public int compareTo(pair one) {
			if (this.first < one.first)
				return -1;
			if (this.first > one.first)
				return 1;
			if (this.second < one.second)
				return -1;
			if (this.second > one.second)
				return 1;
			return 0;
		}

	}

	/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`````````````````````````^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
	static class InputReader {
		private byte[] buf = new byte[8000];
		private int index;
		private int total;
		private InputStream in;
		// BufferedReader br = new BufferedReader(new
		// InputStreamReader(System.in));

		public InputReader(InputStream stream) {
			in = stream;
		}

		public int scan() {
			if (total == -1)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanlong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		private int scanInt() {
			int integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scandouble() {
			double doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		private float scanfloat() {
			float doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		public String scanstring() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public String scan_nextLine() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(n);
				n = scan();
			} while (!isEndOfLine(n));
			return res.toString();
		}

		public boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
		/// Input module

		public int nextInt() {
			return scanInt();
		}

		public long nextLong() {
			return scanlong();
		}

		public double nextDouble() {
			return scandouble();
		}

		public float nextFloat() {
			return scanfloat();
		}

		public String next() {
			return scanstring();
		}

		public String nextLine() throws IOException {
			return scan_nextLine();
		}

		public int[] readintArray(int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}

		public Integer[] readIntegerArray(int size) {
			Integer[] array = new Integer[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}
	}

}


import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main {
	public static void main(String[] args) throws Exception {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		int[] dx = { 1, 0, -1, 0, -1, -1, 1, 1 },
			  dy = { 0, 1, 0, -1, -1, 1 - 1, 1 };
		int MAX = (int) (1e5+10);

		// GCD && LCM
		long gcd(long a, long b) {
			return b == 0 ? a : gcd(b, a % b);
		}

		long lcm(long a, long b) {
			return a * (b / gcd(a, b));
		}

		// REverse a String
		String rev(String s) {
			return new StringBuilder(s).reverse().toString();
		}

		/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLUTION IS RIGHT HERE^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

		public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
			int n = in.nextInt(),m = in.nextInt();
			int[] l = new int[m] , r = new int[m];
			int min = Integer.MAX_VALUE;
			for(int i = 0; i < m; i++){
				l[i] = in.nextInt();
				r[i] = in.nextInt();
				if(r[i]-l[i]< min)
					min = r[i]-l[i];
			}
			out.println(min+1);
			int[] res = new int[n];
			fill(res,-1);
			for(int i = 0; i < m; i++){
				if(min == r[i]-l[i]){
					//out.println(min+" "+l[i]+" "+r[i]);
				for(int j = l[i]-1,k=0; j < r[i]; j++){
					if(res[j] == -1){
						//out.println((j+1)+" b");
						res[j] = k++;
					}
				}
				}
			}
			for(int i = 0; i < m; i++){
				//if(min == r[i]-l[i])
				for(int j = l[i]-1,k=0; j < r[i]; j++){
					//out.println(l[i]+" "+r[i]);
					if(res[j] == -1){
						res[j] = k++;
					}
				}
			}
			for(int i = 0; i < n; i++){
				if(res[i] == -1)
					res[i] = 0;
				out.print(res[i]+" ");
			}
		}
	}

	// pair class
	static class pair implements Comparable<pair> {
		int first, second;

		public pair() {
			this.first = 0;
			this.second = 0;
		}

		public pair(int f, int s) {
			this.first = f;
			this.second = s;
		}

		@Override
		public int compareTo(pair one) {
			if (this.first < one.first)
				return -1;
			if (this.first > one.first)
				return 1;
			if (this.second < one.second)
				return -1;
			if (this.second > one.second)
				return 1;
			return 0;
		}

	}

	/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`````````````````````````^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
	static class InputReader {
		private byte[] buf = new byte[8000];
		private int index;
		private int total;
		private InputStream in;
		// BufferedReader br = new BufferedReader(new
		// InputStreamReader(System.in));

		public InputReader(InputStream stream) {
			in = stream;
		}

		public int scan() {
			if (total == -1)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanlong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		private int scanInt() {
			int integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scandouble() {
			double doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		private float scanfloat() {
			float doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		public String scanstring() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public String scan_nextLine() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(n);
				n = scan();
			} while (!isEndOfLine(n));
			return res.toString();
		}

		public boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
		/// Input module

		public int nextInt() {
			return scanInt();
		}

		public long nextLong() {
			return scanlong();
		}

		public double nextDouble() {
			return scandouble();
		}

		public float nextFloat() {
			return scanfloat();
		}

		public String next() {
			return scanstring();
		}

		public String nextLine() throws IOException {
			return scan_nextLine();
		}

		public int[] readintArray(int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}

		public Integer[] readIntegerArray(int size) {
			Integer[] array = new Integer[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}
	}

}


import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main {
	public static void main(String[] args) throws Exception {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		int[] dx = { 1, 0, -1, 0, -1, -1, 1, 1 },
			  dy = { 0, 1, 0, -1, -1, 1 - 1, 1 };
		int MAX = (int) (1e5+10);

		// GCD && LCM
		long gcd(long a, long b) {
			return b == 0 ? a : gcd(b, a % b);
		}

		long lcm(long a, long b) {
			return a * (b / gcd(a, b));
		}

		// REverse a String
		String rev(String s) {
			return new StringBuilder(s).reverse().toString();
		}

		/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLUTION IS RIGHT HERE^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

		public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
			int n = in.nextInt(),m = in.nextInt();
			int[] l = new int[m] , r = new int[m];
			pair[] pair = new pair[m];
			int min = Integer.MAX_VALUE;
			for(int i = 0; i < m; i++){
				l[i] = in.nextInt();
				r[i] = in.nextInt();
				pair[i] = new pair(l[i],r[i]);
				if(r[i]-l[i]< min)
					min = r[i]-l[i];
			}
			out.println(min+1);
			int[] res = new int[n];
			sort(pair);
			fill(res,-1);
			for(int i = 0; i < m; i++){
				//out.println(pair[i].first+" "+pair[i].second+" qq");
				if(min == pair[i].second-pair[i].first){
					//out.println(min+" "+l[i]+" "+r[i]);
				for(int j = pair[i].first-1,k=0; j < pair[i].second; j++){
					if(res[j] == -1){
						//out.println((j+1)+" b");
						res[j] = k++;
					}else if(k == res[j])
						k++;
				}
				}
			}
			for(int i = 0; i < m; i++){
				//if(min == r[i]-l[i])
				for(int j = pair[i].first-1,k=0; j < pair[i].second; j++){
					//out.println(l[i]+" "+r[i]);
					if(res[j] == -1){
						res[j] = k++;
					}
				}
			}
			for(int i = 0; i < n; i++){
				if(res[i] == -1)
					res[i] = 0;
				out.print(res[i]+" ");
			}
		}
	}

	// pair class
	static class pair implements Comparable<pair> {
		int first, second;

		public pair() {
			this.first = 0;
			this.second = 0;
		}

		public pair(int f, int s) {
			this.first = f;
			this.second = s;
		}

		@Override
		public int compareTo(pair one) {
			if (this.first < one.first)
				return -1;
			if (this.first > one.first)
				return 1;
			return 0;
		}

	}

	/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`````````````````````````^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
	static class InputReader {
		private byte[] buf = new byte[8000];
		private int index;
		private int total;
		private InputStream in;
		// BufferedReader br = new BufferedReader(new
		// InputStreamReader(System.in));

		public InputReader(InputStream stream) {
			in = stream;
		}

		public int scan() {
			if (total == -1)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanlong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		private int scanInt() {
			int integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scandouble() {
			double doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		private float scanfloat() {
			float doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		public String scanstring() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public String scan_nextLine() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(n);
				n = scan();
			} while (!isEndOfLine(n));
			return res.toString();
		}

		public boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
		/// Input module

		public int nextInt() {
			return scanInt();
		}

		public long nextLong() {
			return scanlong();
		}

		public double nextDouble() {
			return scandouble();
		}

		public float nextFloat() {
			return scanfloat();
		}

		public String next() {
			return scanstring();
		}

		public String nextLine() throws IOException {
			return scan_nextLine();
		}

		public int[] readintArray(int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}

		public Integer[] readIntegerArray(int size) {
			Integer[] array = new Integer[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}
	}

}


import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main {
	public static void main(String[] args) throws Exception {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		int[] dx = { 1, 0, -1, 0, -1, -1, 1, 1 },
			  dy = { 0, 1, 0, -1, -1, 1 - 1, 1 };
		int MAX = (int) (1e5+10);

		// GCD && LCM
		long gcd(long a, long b) {
			return b == 0 ? a : gcd(b, a % b);
		}

		long lcm(long a, long b) {
			return a * (b / gcd(a, b));
		}

		// REverse a String
		String rev(String s) {
			return new StringBuilder(s).reverse().toString();
		}

		/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLUTION IS RIGHT HERE^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

		public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
			int n = in.nextInt(),m = in.nextInt();
			int[] l = new int[m] , r = new int[m];
			//pair[] pair = new pair[m];
			int min = Integer.MAX_VALUE;
			for(int i = 0; i < m; i++){
				l[i] = in.nextInt();
				r[i] = in.nextInt();
				//pair[i] = new pair(l[i],r[i]);
				if(r[i]-l[i]< min)
					min = r[i]-l[i];
			}
			out.println(min+1);
			//int[] res = new int[n];
			/*sort(pair);
			fill(res,-1);
			for(int i = 0; i < m; i++){
				//out.println(pair[i].first+" "+pair[i].second+" qq");
				if(min == pair[i].second-pair[i].first){
					//out.println(min+" "+l[i]+" "+r[i]);
				for(int j = pair[i].first-1,k=0; j < pair[i].second; j++){
					if(res[j] == -1){
						//out.println((j+1)+" b");
						res[j] = k++;
					}else if(k == res[j])
						k++;
				}
				}
			}
			for(int i = 0; i < m; i++){
				//if(min == r[i]-l[i])
				for(int j = pair[i].first-1,k=0; j < pair[i].second; j++){
					//out.println(l[i]+" "+r[i]);
					if(res[j] == -1){
						res[j] = k++;
					}
				}
			}*/
			for(int i = 0,k=0; i < n; i++){
				if(k > min)
					k = 0;
				out.print(k+" ");
				k++;
			}
		}
	}

	// pair class
	static class pair implements Comparable<pair> {
		int first, second;

		public pair() {
			this.first = 0;
			this.second = 0;
		}

		public pair(int f, int s) {
			this.first = f;
			this.second = s;
		}

		@Override
		public int compareTo(pair one) {
			if (this.first < one.first)
				return -1;
			if (this.first > one.first)
				return 1;
			return 0;
		}

	}

	/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`````````````````````````^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
	static class InputReader {
		private byte[] buf = new byte[8000];
		private int index;
		private int total;
		private InputStream in;
		// BufferedReader br = new BufferedReader(new
		// InputStreamReader(System.in));

		public InputReader(InputStream stream) {
			in = stream;
		}

		public int scan() {
			if (total == -1)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanlong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		private int scanInt() {
			int integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scandouble() {
			double doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		private float scanfloat() {
			float doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		public String scanstring() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public String scan_nextLine() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(n);
				n = scan();
			} while (!isEndOfLine(n));
			return res.toString();
		}

		public boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
		/// Input module

		public int nextInt() {
			return scanInt();
		}

		public long nextLong() {
			return scanlong();
		}

		public double nextDouble() {
			return scandouble();
		}

		public float nextFloat() {
			return scanfloat();
		}

		public String next() {
			return scanstring();
		}

		public String nextLine() throws IOException {
			return scan_nextLine();
		}

		public int[] readintArray(int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}

		public Integer[] readIntegerArray(int size) {
			Integer[] array = new Integer[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}
	}

}


import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main {
	public static void main(String[] args) throws Exception {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		int[] dx = { 1, 0, -1, 0, -1, -1, 1, 1 },
			  dy = { 0, 1, 0, -1, -1, 1 - 1, 1 };
		int MAX = (int) (1e5+10);

		// GCD && LCM
		long gcd(long a, long b) {
			return b == 0 ? a : gcd(b, a % b);
		}

		long lcm(long a, long b) {
			return a * (b / gcd(a, b));
		}

		// REverse a String
		String rev(String s) {
			return new StringBuilder(s).reverse().toString();
		}

		/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLUTION IS RIGHT HERE^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

		public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
			int n = in.nextInt(),m = in.nextInt();
			int[] l = new int[m] , r = new int[m];
			//pair[] pair = new pair[m];
			int min = Integer.MAX_VALUE;
			for(int i = 0; i < m; i++){
				l[i] = in.nextInt();
				r[i] = in.nextInt();
				//pair[i] = new pair(l[i],r[i]);
				if(r[i]-l[i]< min)
					min = r[i]-l[i];
			}
			out.println(min+1);
			//int[] res = new int[n];
			/*sort(pair);
			fill(res,-1);
			for(int i = 0; i < m; i++){
				//out.println(pair[i].first+" "+pair[i].second+" qq");
				if(min == pair[i].second-pair[i].first){
					//out.println(min+" "+l[i]+" "+r[i]);
				for(int j = pair[i].first-1,k=0; j < pair[i].second; j++){
					if(res[j] == -1){
						//out.println((j+1)+" b");
						res[j] = k++;
					}else if(k == res[j])
						k++;
				}
				}
			}
			for(int i = 0; i < m; i++){
				//if(min == r[i]-l[i])
				for(int j = pair[i].first-1,k=0; j < pair[i].second; j++){
					//out.println(l[i]+" "+r[i]);
					if(res[j] == -1){
						res[j] = k++;
					}
				}
			}*/
			for(int i = 0,k=0; i < n; i++){
				if(k > min)
					k = 0;
				out.print(k+" ");
			}
		}
	}

	// pair class
	static class pair implements Comparable<pair> {
		int first, second;

		public pair() {
			this.first = 0;
			this.second = 0;
		}

		public pair(int f, int s) {
			this.first = f;
			this.second = s;
		}

		@Override
		public int compareTo(pair one) {
			if (this.first < one.first)
				return -1;
			if (this.first > one.first)
				return 1;
			return 0;
		}

	}

	/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`````````````````````````^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
	static class InputReader {
		private byte[] buf = new byte[8000];
		private int index;
		private int total;
		private InputStream in;
		// BufferedReader br = new BufferedReader(new
		// InputStreamReader(System.in));

		public InputReader(InputStream stream) {
			in = stream;
		}

		public int scan() {
			if (total == -1)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanlong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		private int scanInt() {
			int integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scandouble() {
			double doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		private float scanfloat() {
			float doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		public String scanstring() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public String scan_nextLine() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(n);
				n = scan();
			} while (!isEndOfLine(n));
			return res.toString();
		}

		public boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
		/// Input module

		public int nextInt() {
			return scanInt();
		}

		public long nextLong() {
			return scanlong();
		}

		public double nextDouble() {
			return scandouble();
		}

		public float nextFloat() {
			return scanfloat();
		}

		public String next() {
			return scanstring();
		}

		public String nextLine() throws IOException {
			return scan_nextLine();
		}

		public int[] readintArray(int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}

		public Integer[] readIntegerArray(int size) {
			Integer[] array = new Integer[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}
	}

}


import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main {
	public static void main(String[] args) throws Exception {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		int[] dx = { 1, 0, -1, 0, -1, -1, 1, 1 },
			  dy = { 0, 1, 0, -1, -1, 1 - 1, 1 };
		int MAX = (int) (1e5+10);

		// GCD && LCM
		long gcd(long a, long b) {
			return b == 0 ? a : gcd(b, a % b);
		}

		long lcm(long a, long b) {
			return a * (b / gcd(a, b));
		}

		// REverse a String
		String rev(String s) {
			return new StringBuilder(s).reverse().toString();
		}

		/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLUTION IS RIGHT HERE^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

		public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
			int n = in.nextInt(),m = in.nextInt();
			int[] l = new int[m] , r = new int[m];
			int min = Integer.MAX_VALUE;
			for(int i = 0; i < m; i++){
				l[i] = in.nextInt();
				r[i] = in.nextInt();
				if(r[i]-l[i]< min)
					min = r[i]-l[i];
			}
			out.println(min+1);
			int[] res = new int[n];
			fill(res,-1);
			for(int i = 0; i < m; i++){
				if(min == r[i]-l[i])
				for(int j = l[i]-1; j < r[i]; j++){
					if(res[j] == -1){
						res[j] = j-l[i]+1;
					}
				}
			}
			for(int i = 0; i < m; i++){
				//if(min == r[i]-l[i])
				for(int j = l[i]-1; j < r[i]; j++){
					if(res[j] == -1){
						res[j] = j-l[i]+1;
					}
				}
			}
			for(int i = 0; i < n; i++)
				out.print(res[i]+" ");
		}
	}

	// pair class
	static class pair implements Comparable<pair> {
		int first, second;

		public pair() {
			this.first = 0;
			this.second = 0;
		}

		public pair(int f, int s) {
			this.first = f;
			this.second = s;
		}

		@Override
		public int compareTo(pair one) {
			if (this.first < one.first)
				return -1;
			if (this.first > one.first)
				return 1;
			if (this.second < one.second)
				return -1;
			if (this.second > one.second)
				return 1;
			return 0;
		}

	}

	/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^`````````````````````````^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
	static class InputReader {
		private byte[] buf = new byte[8000];
		private int index;
		private int total;
		private InputStream in;
		// BufferedReader br = new BufferedReader(new
		// InputStreamReader(System.in));

		public InputReader(InputStream stream) {
			in = stream;
		}

		public int scan() {
			if (total == -1)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanlong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		private int scanInt() {
			int integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scandouble() {
			double doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		private float scanfloat() {
			float doubll = 0;
			int n = scan();
			int neg = 1;
			while (isWhiteSpace(n))
				n = scan();
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doubll *= 10;
					doubll += n - '0';
					n = scan();
				}
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doubll += (n - '0') * temp;
						n = scan();
					}
				}
			}
			return neg * doubll;
		}

		public String scanstring() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public String scan_nextLine() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(n);
				n = scan();
			} while (!isEndOfLine(n));
			return res.toString();
		}

		public boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
		/// Input module

		public int nextInt() {
			return scanInt();
		}

		public long nextLong() {
			return scanlong();
		}

		public double nextDouble() {
			return scandouble();
		}

		public float nextFloat() {
			return scanfloat();
		}

		public String next() {
			return scanstring();
		}

		public String nextLine() throws IOException {
			return scan_nextLine();
		}

		public int[] readintArray(int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}

		public Integer[] readIntegerArray(int size) {
			Integer[] array = new Integer[size];
			for (int i = 0; i < size; i++) {
				array[i] = nextInt();
			}
			return array;
		}
	}

}


/*
 *created by Kraken on 04-05-2020 at 14:25
 */
//package com.kraken.cf.practice;

import java.util.*;
import java.io.*;

public class A739 {

  public static void main(String[] args) {
    FastReader sc = new FastReader();
    int n = sc.nextInt(), m = sc.nextInt();
    int len = Integer.MAX_VALUE;
    while (m-- > 0) {
      int a = sc.nextInt(), b = sc.nextInt();
      len = Math.min(len, b - a + 1);
    }
    StringBuilder sb = new StringBuilder();
    int cnt = 0, curr = 0;
    while (cnt < n) {
      sb.append(curr + " ");
      cnt++;
      curr++;
      if (curr == len) curr = 0;
    }
    System.out.println(sb);
  }

  static class FastReader {

    BufferedReader br;

    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        }
        catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      }
      catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


/*
 *created by Kraken on 04-05-2020 at 14:25
 */
//package com.kraken.cf.practice;

import java.util.*;
import java.io.*;

public class A739 {

  public static void main(String[] args) {
    FastReader sc = new FastReader();
    int n = sc.nextInt(), m = sc.nextInt();
    int len = Integer.MAX_VALUE;
    while (m-- > 0) {
      int a = sc.nextInt(), b = sc.nextInt();
      len = Math.min(len, b - a + 1);
    }
    StringBuilder sb = new StringBuilder();
    int cnt = 0, curr = 0;
    while (cnt < n) {
      sb.append(curr + " ");
      cnt++;
      curr++;
      if (curr == len) curr = 0;
    }
    System.out.println(len + "\n" + sb);
  }

  static class FastReader {

    BufferedReader br;

    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        }
        catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      }
      catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


import java.util.Scanner;

public class AlyonaAndMex {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < m; i++) {
            int currentSeg = -1 * (in.nextInt() - in.nextInt()) + 1;
            if (currentSeg < min) min = currentSeg;
        }
        System.out.println(min);
        for (int i = 0; i < n; i++) {
            System.out.print(i % min + " ");
        }
    }
}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Solution {

	// Complete the sockMerchant function below.

	public static void main(String[] args) throws IOException {
		class InputReader {
			BufferedReader reader;
			StringTokenizer tokenizer;

			public InputReader(InputStream stream) {
				reader = new BufferedReader(new InputStreamReader(stream));
				tokenizer = null;
			}

			public String next() {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return tokenizer.nextToken();
			}

			public long nextLong() {
				return Long.parseLong(next());
			}

			public int nextInt() {
				return Integer.parseInt(next());
			}

		}
		InputReader y = new InputReader(System.in);
		int n = y.nextInt();
		int m = y.nextInt();
		int [] ar = new int [n];
		int dif = Integer.MAX_VALUE;
		for (int i = 0; i < m; i++) {
			int x = - y.nextInt() + y.nextInt()+1;
			if(x<dif) {
				dif = x;
			}
		}
		System.out.println(dif);
		for (int i = 0; i < ar.length; i++) {
			ar[i]= i % dif;
			System.out.print(ar[i]+" ");
		}

	}
}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Solution {

	// Complete the sockMerchant function below.

	public static void main(String[] args) throws IOException {
		class InputReader {
			BufferedReader reader;
			StringTokenizer tokenizer;

			public InputReader(InputStream stream) {
				reader = new BufferedReader(new InputStreamReader(stream));
				tokenizer = null;
			}

			public String next() {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return tokenizer.nextToken();
			}

			public long nextLong() {
				return Long.parseLong(next());
			}

			public int nextInt() {
				return Integer.parseInt(next());
			}

		}
		InputReader y = new InputReader(System.in);
		int n = y.nextInt();
		int m = y.nextInt();
		int [] ar = new int [n];
		int dif = Integer.MAX_VALUE;
		for (int i = 0; i < m; i++) {
			int x = - y.nextInt() + y.nextInt()+1;
			if(x<dif) {
				dif = x;
			}
		}
		System.out.println(dif);
		for (int i = 0; i < ar.length; i++) {
			ar[i]= i % dif;
			System.out.print(ar[i]);
		}

	}
}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Solution {

	// Complete the sockMerchant function below.

	public static void main(String[] args) throws IOException {
		class InputReader {
			BufferedReader reader;
			StringTokenizer tokenizer;

			public InputReader(InputStream stream) {
				reader = new BufferedReader(new InputStreamReader(stream));
				tokenizer = null;
			}

			public String next() {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return tokenizer.nextToken();
			}

			public long nextLong() {
				return Long.parseLong(next());
			}

			public int nextInt() {
				return Integer.parseInt(next());
			}

		}
		InputReader y = new InputReader(System.in);
		int n = y.nextInt();
		int m = y.nextInt();
		int [] ar = new int [n];
		int dif = Integer.MAX_VALUE;
		for (int i = 0; i < m; i++) {
			int x = - y.nextInt() + y.nextInt();
			if(x<dif) {
				dif = x;
			}
		}
		System.out.println(dif);
		for (int i = 0; i < ar.length; i++) {
			ar[i]= i % dif;
			System.out.print(ar[i]);
		}

	}
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;

public class main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1};
    public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1};

    public static void main(String[] args) throws IOException{
        st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());
        int minDist = (1 << 30);
        for(int i = 0; i < M; i++){
            st = new StringTokenizer(br.readLine());
            int a =Integer.parseInt(st.nextToken());
            int b =Integer.parseInt(st.nextToken());
            minDist = Math.min(minDist, b-a+1);
        }
        pw.print(minDist + "\n");
        int cnt = 0;
        for(int i = 0; i < N; i++){
            if(i != 0) pw.print(" ");
            pw.print(cnt);
            cnt = (cnt + 1) % minDist;
        }
        pw.print("\n");
        pw.close();
        br.close();
    }
}

class Pair implements Comparable<Pair>{
    public int a, b;

    Pair(int _a, int _b){
        a = _a;
        b = _b;
    }

    public int compareTo(Pair p){
        if(a != p.a) return a - p.a;
        return b - p.b;
    }
}


import java.io.*;
import java.math.*;
import java.util.*;

/**
 *
 * @author Saju
 *
 */

public class Main {

    private static int dx[] = { 1, 0, -1, 0 };
    private static int dy[] = { 0, -1, 0, 1 };

    private static final long INF = (long) Math.pow(10, 16);
    private static final int INT_INF = Integer.MAX_VALUE;
    private static final long NEG_INF = Long.MIN_VALUE;
    private static final int NEG_INT_INF = Integer.MIN_VALUE;
    private static final double EPSILON = 1e-10;

    private static final long MAX = (long) 1e12;

    private static final long MOD = 1000000007;

    private static final int MAXN = 200001;
    private static final int MAXA = 1000007;
    private static final int MAXLOG = 22;
    private static final double PI = Math.acos(-1);

	public static void main(String[] args) throws IOException {

		InputReader in = new InputReader(System.in);
//		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

//         InputReader in = new InputReader(new FileInputStream("src/test.in"));
//         PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/test.out")));

/*

*/

		int n = in.nextInt();
		int m = in.nextInt();

		int min = INT_INF;

		Pair[] pairs = new Pair[m];
		for(int i = 0; i < m; i++) {
			pairs[i] = new Pair(in.nextInt(), in.nextInt());
			min = min(min, pairs[i].r - pairs[i].l + 1);
		}
//		System.out.println(min);
		int arr[] = new int[n];
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			arr[i] = cnt++;
			if(cnt == min) {
				cnt = 0;
			}
		}

		for(int i = 0; i < n; i++) {
			out.print(arr[i]);
			if(i < n - 1) {
				out.print(" ");
			}
			else {
				out.println();
			}
		}

		in.close();
		out.flush();
		out.close();
		System.exit(0);
	}

	private static class Pair{
		int l;
		int r;
		Pair(int l, int r){
			this.l = l;
			this.r = r;
		}
	}

	/*
	 * return the number of elements in list that are less than or equal to the val
	 */
	private static long upperBound(List<Long> list, long val) {
		int start = 0;
		int len = list.size();
		int end = len - 1;
		int mid = 0;

		while (true) {
			if (start > end) {
				break;
			}
			mid = (start + end) / 2;
			long v = list.get(mid);
			if (v == val) {
				start = mid;
				while(start < end) {
					mid = (start + end) / 2;
					if(list.get(mid) == val) {
						if(mid + 1 < len && list.get(mid + 1) == val) {
							start = mid + 1;
						}
						else {
							return mid + 1;
						}
					}
					else {
						end = mid - 1;
					}
				}
				return start + 1;
			}
			if (v > val) {
				end = mid - 1;
			} else {
				start = mid + 1;
			}
		}
		if (list.get(mid) < val) {
			return mid + 1;
		}
		return mid;
	}

	private static boolean isPalindrome(String str) {
		StringBuilder sb = new StringBuilder();
		sb.append(str);
		String str1 = sb.reverse().toString();
		return str.equals(str1);
	}

	private static String getBinaryStr(long n, int j) {
		String str = Long.toBinaryString(n);
		int k = str.length();
		for (int i = 1; i <= j - k; i++) {
			str = "0" + str;
		}

		return str;
	}

	private static long modInverse(long r) {
		return bigMod(r, MOD - 2, MOD);
	}

	private static long bigMod(long n, long k, long m) {

        long ans = 1;
        while (k > 0) {
            if ((k & 1) == 1) {
                ans = (ans * n) % m;
            }
            n = (n * n) % m;
            k >>= 1;
        }
        return ans;
    }

	private static long ceil(long n, long x) {
		long div = n / x;
        if(div * x != n) {
            div++;
        }
        return div;
	}

    private static int ceil(int n, int x) {
        int div = n / x;
        if(div * x != n) {
            div++;
        }
        return div;
    }

    private static int abs(int x) {
        if (x < 0) {
            return -x;
        }
        return x;
    }

    private static double abs(double x) {
        if (x < 0) {
            return -x;
        }
        return x;
    }

    private static long abs(long x) {
        if(x < 0) {
            return -x;
        }
        return x;
    }

    private static long lcm(long a, long b) {
        return (a * b) / gcd(a, b);
    }

    private static int lcm(int a, int b) {
        return (a * b) / gcd(a, b);
    }

    private static int gcd(int a, int b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    private static long gcd(long a, long b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    private static int log(long x, int base) {
        return (int) (Math.log(x) / Math.log(base));
    }

    private static int log(long x, long base) {
        return (int) (Math.log(x) / Math.log(base));
    }

    private static long min(long a, long b) {
        if (a < b) {
            return a;
        }
        return b;
    }

    private static int min(int a, int b) {
        if (a < b) {
            return a;
        }
        return b;
    }

    private static long max(long a, long b) {
        if (a < b) {
            return b;
        }
        return a;
    }

    private static int max(int a, int b) {
        if (a < b) {
            return b;
        }
        return a;
    }

    private static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());

                }
            } catch (IOException e) {
                return null;
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            String line = null;
            try {
                tokenizer = null;
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public boolean hasNext() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (Exception e) {
                return false;
            }
            return true;
        }

        public int[] nextIntArr(int n) {
        	int arr[] = new int[n];
    		for(int i = 0; i < n; i++) {
    			arr[i] = nextInt();
    		}
    		return arr;
        }

        public long[] nextLongArr(int n) {
        	long arr[] = new long[n];
    		for(int i = 0; i < n; i++) {
    			arr[i] = nextLong();
    		}
    		return arr;
        }

        public int[] nextIntArr1(int n) {
        	int arr[] = new int[n + 1];
    		for(int i = 1; i <= n; i++) {
    			arr[i] = nextInt();
    		}
    		return arr;
        }

        public long[] nextLongArr1(int n) {
        	long arr[] = new long[n + 1];
    		for(int i = 1; i <= n; i++) {
    			arr[i] = nextLong();
    		}
    		return arr;
        }

        public void close() {
        	try {
        		if(reader != null) {
        			reader.close();
        		}
        	}
        	catch(Exception e) {

        	}

        }
    }

}