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] + " ");
		}

		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) {

        	}

        }
    }

}


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;
			}
		}
		System.out.println(Arrays.toString(arr));

		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) {

        	}

        }
    }

}


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;
			}
		}

//		int mex = INT_INF;
//		for(int i = 0; i < m; i++) {
//			int l = pairs[i].l - 1;
//			int r = pairs[i].r - 1;
//			int len = r - l + 1;
//			if(len >= min) {
//				mex = min(mex, min);
//			}
//			else {
//
//			}
//		}

		out.println(min);

		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) {

        	}

        }
    }

}


import java.io.*;
import java.util.*;
public class CF739A
{
    public static void main(String[] args)throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String t1=br.readLine();
        String[] t2=t1.split(" ");
        int n=Integer.parseInt(t2[0]);
        int m=Integer.parseInt(t2[1]);
        int[][] sa=new int[m][2];
        for(int i=0;i<m;i++)
        {
            String t3=br.readLine();
            String[] t4=t3.split(" ");
            sa[i][0]=Integer.parseInt(t4[0]);
            sa[i][1]=Integer.parseInt(t4[1]);
        }
        int min=Integer.MAX_VALUE;
        for(int j=0;j<m;j++)
        {
            min=Math.min(min,sa[j][1]-sa[j][0]+1);
        }
        System.out.println(min);
        int mark=0;
        for(int k=0;k<n;k++)
        {
            System.out.print(mark+" ");
            if(mark==min-1)
            {
                mark=0;
            }
            else
            {
                mark++;
            }
        }
        System.out.println();
    }
}

/*
import java.io.*;
import java.util.*;
public class CF739A
{
public static void main(String[] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String t1=br.readLine();
String[] t2=t1.split(" ");
int n=Integer.parseInt(t2[0]);
int m=Integer.parseInt(t2[1]);
int[][] sa=new int[m][2];
for(int i=0;i<m;i++)
{
String t3=br.readLine();
String[] t4=t3.split(" ");
sa[i][0]=Integer.parseInt(t4[0]);
sa[i][1]=Integer.parseInt(t4[1]);
}
int[] arr=new int[n];
Arrays.fill(arr,-1);
int[] mark=new int[n+1];
Arrays.fill(mark,-1);
for(int i=0;i<m;i++)
{
Arrays.fill(mark,-1);
for(int j=sa[i][0]-1;j<=sa[i][1]-1;j++)
{
if(arr[j]!=-1)
{
mark[arr[j]]=1;
}
}
for(int j=sa[i][0]-1;j<=sa[i][1]-1;j++)
{
if(arr[j]==-1)
{
for(int k=0;k<=n;k++)
{
if(mark[k]==-1)
{
mark[k]=1;
arr[j]=k;
break;
}
}
}
}

for(int l=0;l<n;l++)
{
System.out.print(arr[l]+" ");
}
System.out.println();
}
for(int l=0;l<n;l++)
{
System.out.print(arr[l]+" ");
}
System.out.println();
}
}
 */


import java.util.Scanner;

public class CF739A {
	int sizeOfArray;
	int numSubArrays;
	int shortest = Integer.MAX_VALUE;
	public CF739A(){
		getData();
		execute();
	}
	public void getData(){
		Scanner scan = new Scanner(System.in);
		sizeOfArray = scan.nextInt();
		numSubArrays = scan.nextInt();
		for(int i = 0; i < numSubArrays; i++){
			int a = scan.nextInt();
			int b = scan.nextInt();
			if(b-a+1<shortest)
				shortest = b-a+1;
		}
	}
	public void execute(){
		StringBuilder sb = new StringBuilder();
		int count = 0;
		for(int i = 0; i<sizeOfArray;i++){
			sb.append(count + " ");
			count = (count+1)%shortest;
		}
		System.out.println(shortest);
		System.out.println(sb.toString());
	}
	public static void main(String[] args){
		CF739A app = new CF739A();
	}
}


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

public class Main {

    static class Solution {
        int n,m;
        P[] a;

        FastReader fr;
        BufferedWriter bw;

        class P {
            int x,y;
            P(int x,int y) {
                this.x = x;
                this.y = y;
            }

            int len() {
                return y-x+1;
            }
        }

        void solve() throws Exception{
            fr = new FastReader();
            bw = new BufferedWriter(new OutputStreamWriter(System.out));

            n = fr.nextInt(); m = fr.nextInt();
            a = new P[m];

            P pmin = new P(0,(int) 2e9);
            for(int i=0;i<m;i++) {
                int u = fr.nextInt(), v = fr.nextInt();
                a[i] = new P(u,v);
                if(a[i].len() < pmin.len()) pmin = a[i];
            }

            int[] arr = new int[n+1];
            for(int i=pmin.x+1;i<=pmin.y;i++) arr[i] = arr[i-1]+1;
            int cv = pmin.len()-1;
            for(int i=pmin.x-1;i>=1;i--) {
                arr[i] = cv;
                cv--;
                if(cv < 0) cv = pmin.len()-1;
            }
            cv = 0;
            for(int i=pmin.y+1;i<=n;i++) {
                arr[i] = cv;
                cv++;
                if(cv >= pmin.len()) cv = 0;
            }
            bw.write(pmin.len()+"\n");
            for(int i=1;i<=n;i++) bw.write(arr[i]+" ");
            bw.close();
        }

    }

    public static void main(String[] args) throws Exception {
        new Solution().solve();
    }

    static class FastReader {
        BufferedReader bf;
        StringTokenizer st;

        FastReader() {
            st = null;
            try {
                bf = new BufferedReader(new InputStreamReader(System.in));
            } catch(Exception e) {
                e.printStackTrace();
            }
        }

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

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

}


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

public class Main {

    static class Solution {
        int n,m;
        P[] a;

        FastReader fr;
        BufferedWriter bw;

        class P {
            int x,y;
            P(int x,int y) {
                this.x = x;
                this.y = y;
            }

            int len() {
                return y-x+1;
            }
        }

        void solve() throws Exception{
            fr = new FastReader();
            bw = new BufferedWriter(new OutputStreamWriter(System.out));

            n = fr.nextInt(); m = fr.nextInt();
            a = new P[m];

            P pmin = new P(0,(int) 2e9);
            for(int i=0;i<m;i++) {
                int u = fr.nextInt(), v = fr.nextInt();
                a[i] = new P(u,v);
                if(a[i].len() < pmin.len()) pmin = a[i];
            }

            int[] arr = new int[n+1];
            for(int i=pmin.x+1;i<=pmin.y;i++) arr[i] = arr[i-1]+1;
            int cv = pmin.len()-1;
            for(int i=pmin.x-1;i>=1;i--) {
                arr[i] = cv;
                cv--;
                if(cv < 0) cv = pmin.len()-1;
            }
            cv = 0;
            for(int i=pmin.y+1;i<=n;i++) {
                arr[i] = cv;
                cv++;
                if(cv >= pmin.len()) cv = 0;
            }
            bw.write(a[0].len()+"\n");
            for(int i=1;i<=n;i++) bw.write(arr[i]+" ");
            bw.close();
        }

    }

    public static void main(String[] args) throws Exception {
        new Solution().solve();
    }

    static class FastReader {
        BufferedReader bf;
        StringTokenizer st;

        FastReader() {
            st = null;
            try {
                bf = new BufferedReader(new InputStreamReader(System.in));
            } catch(Exception e) {
                e.printStackTrace();
            }
        }

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

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

}


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

public class Main {

    static class Solution {
        int n,m;
        P[] a;

        FastReader fr;
        BufferedWriter bw;

        class P {
            int x,y;
            P(int x,int y) {
                this.x = x;
                this.y = y;
            }

            int len() {
                return y-x+1;
            }
        }

        void solve() throws Exception{
            fr = new FastReader();
            bw = new BufferedWriter(new OutputStreamWriter(System.out));

            n = fr.nextInt(); m = fr.nextInt();
            a = new P[m];

            for(int i=1;i<=m;i++) {
                int u = fr.nextInt(), v = fr.nextInt();
                a[i-1] = new P(u,v);
            }
            Arrays.sort(a,(P x,P y) -> x.len() - y.len());
            int[] arr = new int[n+5];
            for(P p:a) {
                int mx = 0;
                for(int i=p.x;i<=p.y;i++) mx = Math.max(arr[i],mx);
                for(int i=p.x;i<=p.y;i++) if(arr[i] == 0) arr[i] = ++mx;
            }
            for(int i=1;i<=n;i++) if(arr[i] != 0) arr[i]--;
            bw.write(a[0].len()+"\n");
            for(int i=1;i<=n;i++) bw.write(arr[i]+" ");
            bw.close();
        }

    }

    public static void main(String[] args) throws Exception {
        new Solution().solve();
    }

    static class FastReader {
        BufferedReader bf;
        StringTokenizer st;

        FastReader() {
            st = null;
            try {
                bf = new BufferedReader(new InputStreamReader(System.in));
            } catch(Exception e) {
                e.printStackTrace();
            }
        }

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

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

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ilyakor
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    TaskA solver = new TaskA();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskA {

    public void solve(int testNumber, InputReader in, OutputWriter out) {
      int n = in.nextInt();
      int m = in.nextInt();
      int res = n;
      for (int i = 0; i < m; ++i) {
        int l = in.nextInt();
        int r = in.nextInt();
        res = Math.min(res, r - l + 1);
      }
      out.printLine(res);
      for (int i = 0; i < n; ++i) {
        out.print(i % res + " ");
      }
      out.printLine();
    }

  }

  static class OutputWriter {

    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; i++) {
        if (i != 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void printLine(Object... objects) {
      print(objects);
      writer.println();
    }

    public void close() {
      writer.close();
    }

  }

  static class InputReader {

    private InputStream stream;
    private byte[] buffer = new byte[10000];
    private int cur;
    private int count;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public static boolean isSpace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public int read() {
      if (count == -1) {
        throw new InputMismatchException();
      }
      try {
        if (cur >= count) {
          cur = 0;
          count = stream.read(buffer);
          if (count <= 0) {
            return -1;
          }
        }
      } catch (IOException e) {
        throw new InputMismatchException();
      }
      return buffer[cur++];
    }

    public int readSkipSpace() {
      int c;
      do {
        c = read();
      } while (isSpace(c));
      return c;
    }

    public int nextInt() {
      int sgn = 1;
      int c = readSkipSpace();
      if (c == '-') {
        sgn = -1;
        c = read();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        res = res * 10 + c - '0';
        c = read();
      } while (!isSpace(c));
      res *= sgn;
      return res;
    }

  }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Hieu Le
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int minRange = Integer.MAX_VALUE;
            for (int i = 0; i < m; ++i) {
                int left = in.nextInt();
                int right = in.nextInt();
                minRange = Math.min(minRange, right - left + 1);
            }

            out.println(minRange);
            for (int i = 0; i < n; ++i) {
                out.printf("%d ", i % minRange);
            }
            out.println();
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;
        private static final int BUFFER_SIZE = 32768;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), BUFFER_SIZE);
            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 int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            AAlyonaAndMex solver = new AAlyonaAndMex();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class AAlyonaAndMex {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int m = in.readInt();
            int max = n;
            for (int i = 0; i < m; i++) {
                int l = in.readInt();
                int r = in.readInt();
                max = Math.min(max, r - l + 1);
            }
            out.println(max);
            for (int i = 0; i < n; i++) {
                out.append(i % max).append(' ');
            }

        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int m = in.readInt();

            int minLen = Integer.MAX_VALUE;
            for (int i = 0; i < m; i++) {
                int l = in.readInt();
                int r = in.readInt();
                minLen = Math.min(minLen, r - l + 1);
            }
            out.printLine(minLen);
            for (int i = 0; i < n; i++) {
                out.print(" " + (i % minLen));
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

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

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return (c == ' ') || (c == '\n') || (c == '\r') || (c == '\t') || (c == -1);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.close();
        }

        public void printLine(int i) {
            writer.println(i);
        }

    }
}


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

public class Main {

    private static myScanner sc;
    private static PrintWriter pw;

    private static final boolean defaultInAndOutPut = true;

    private static final int numberOfTests = 1;

    private static final String nameOfInAndOutFile = "";
    private static final String fullNameInputFile = nameOfInAndOutFile + ".in";
    private static final String fullNameOutputFile = nameOfInAndOutFile + ".out";

    public static void main(String[] args) throws IOException {
        if (defaultInAndOutPut) {
            setDefaultInAndOutPut();
        } else {
            setInAndOutPutFromFile();
        }
        for (int test = 1; test <= numberOfTests; test++) {
            solve();
            pw.flush();
        }

        pw.close();
    }

    private static void setDefaultInAndOutPut() {
        sc = new myScanner(new BufferedReader(new InputStreamReader(System.in)));
        pw = new PrintWriter(System.out);
    }

    private static void setInAndOutPutFromFile() throws IOException {
        sc = new myScanner(new BufferedReader(new FileReader(new File(fullNameInputFile))));
        pw = new PrintWriter(new File(fullNameOutputFile));
    }

    private static final int intINF = Integer.MAX_VALUE;
    private static final int MOD = 1000000007;
    private static final long longINF = Long.MAX_VALUE;

    private static void solve() {
        int n=sc.nextInt(),m=sc.nextInt();
        int len = intINF;
        for (int i=0;i<m;i++)len=Math.min(-sc.nextInt()+sc.nextInt()+1,len);
        pw.println(len);
        for (int i=0;i<n;){
            for (int j=0;j<len && i<n;j++){
                pw.print(j+" ");
                i++;
            }
        }
    }
}

class myScanner {
    private char[] buffer = new char[1 << 8];
    private int pos = 1;

    private BufferedReader reader;

    public myScanner(BufferedReader reader) {
        this.reader = reader;
    }

    public boolean hasNext() {
        return pos > 0;
    }

    private void loadBuffer() {
        pos = 0;
        try {
            for (int i; (i = reader.read()) != -1; ) {
                char c = (char) i;
                if (c != ' ' && c != '\n' && c != '\t' && c != '\r' && c != '\f') {
                    if (pos == buffer.length) buffer = Arrays.copyOf(buffer, 2 * pos);
                    buffer[pos++] = c;
                } else if (pos != 0) break;
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

    public String current() {
        return String.copyValueOf(buffer, 0, pos);
    }

    public String next() {
        loadBuffer();
        return current();
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

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

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

    public int nextInt(int radix) {
        loadBuffer();
        int result = 0;
        int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;
        for (checkValidNumber(pos > i); i < pos; i++) {
            int digit = buffer[i] - '0';
            checkValidNumber(0 <= digit && digit <= radix - 1);
            result = result * radix + digit;
        }
        return buffer[0] == '-' ? -result : result;
    }

    public long nextLong(int radix) {
        loadBuffer();
        long result = 0;
        int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;
        for (checkValidNumber(pos > i); i < pos; i++) {
            int digit = buffer[i] - '0';
            checkValidNumber(0 <= digit && digit <= radix - 1);
            result = result * radix + digit;
        }
        return buffer[0] == '-' ? -result : result;
    }

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

    public long[] nextArrayLongs(int size) {
        long[] input = new long[size];
        for (int i = 0; i < size; i++) input[i] = nextLong();
        return input;
    }

    public double nextDouble() {
        loadBuffer();
        long result = 0;
        int i = buffer[0] == '-' || buffer[0] == '+' ? 1 : 0;
        long round = 1;
        final int radix = 10;
        boolean hasPoint = false;
        for (checkValidNumber(pos > i); i < pos; i++) {
            int digit = buffer[i] - '0';
            checkValidNumber((0 <= digit && digit <= radix - 1) || (!hasPoint && digit == -2));
            if (digit == -2) hasPoint = true;
            else {
                if (hasPoint) round *= radix;
                result = result * radix + digit;
            }

        }
        return buffer[0] == '-' ? -result / (1.0 * round) : result / (1.0 * round);
    }

    private void checkValidNumber(boolean condition) {
        if (!condition) throw new NumberFormatException(current());
    }
}


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

public class alyonaMex2 {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

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

        long[] a = new long[n];
        int minMex = 0;

        for (int i = 0; i < m; i++) {
            int l = scan.nextInt();
            int r = scan.nextInt();
            if (i == 0) {
                minMex = r - l;
            } else {
                if (minMex > r - l) {
                    minMex = r - l;
                }
            }
        }

        System.out.println(++minMex);

        long counter = 0;

        for (int i = 0; i < n; i++) {
            if (counter < minMex) {
                a[i] = counter;
                counter++;
            } else {
                a[i] = 0;
                counter = 1;
            }

            System.out.print(a[i]);
            if (i != n - 1) {
                System.out.print(" ");
            }
        }
    }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int ranges=sc.nextInt();
        int minrange=n,currRange,s,e;
        for (int i = 0; i <ranges ; i++) {
            currRange=-sc.nextInt()+sc.nextInt();
            if(minrange>currRange)
                minrange=currRange;
        }
        System.out.println(minrange+1);
        int output=0;
        for (int i = 0; i <n ; i++) {
            System.out.print(output);
            if (i!=n-1)
                System.out.print(' ');
            output= output==minrange ? 0:output+1;
        }

    }
}


package com.company;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int ranges=sc.nextInt();
        int maxrange=0,currRange,s,e;
        for (int i = 0; i <ranges ; i++) {
            currRange=-sc.nextInt()+sc.nextInt();
            if(maxrange<currRange)
                maxrange=currRange;
        }
        System.out.println(maxrange-1);
        int output=0;
        for (int i = 0; i <n ; i++) {
            System.out.print(output);
            if (i!=n-1)
                System.out.print(' ');
            output= output==maxrange ? 0:output+1;
        }

    }


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int ranges=sc.nextInt();
        int maxrange=0,currRange,s,e;
        for (int i = 0; i <ranges ; i++) {
            currRange=-sc.nextInt()+sc.nextInt();
            if(maxrange<currRange)
                maxrange=currRange;
        }
        System.out.println(maxrange-1);
        int output=0;
        for (int i = 0; i <n ; i++) {
            System.out.print(output);
            if (i!=n-1)
                System.out.print(' ');
            output= output==maxrange ? 0:output+1;
        }

    }
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int ans = Integer.MAX_VALUE;
        int[] arr = new int[n];
        for (int i = 0; i < m; i++) {
            ans = Math.min(ans, Math.abs(sc.nextInt() - sc.nextInt()) + 1);
        }
        for (int i = 0; i < n; i++) {
            arr[i] = i % ans;
        }
        System.out.println(ans);
        for (int i : arr) {
            System.out.print(i + " ");
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class alyona {

	public static void main(String[] args) throws IOException {
		BufferedReader tec=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out=new PrintWriter(System.out);
		StringTokenizer st=new StringTokenizer(tec.readLine());
		int n=Integer.parseInt(st.nextToken());
		int m=Integer.parseInt(st.nextToken());
		long min=Long.MAX_VALUE;
		for (int i = 0; i < m; i++) {
			st=new StringTokenizer(tec.readLine());
			min=Math.min(min, Math.abs(Long.parseLong(st.nextToken())-Long.parseLong(st.nextToken()))+1);
		}
		out.println(min);
		for (int i = 0; i < n; i++) {
			out.print(i%min);
			if(i!=n-1)
				out.print(" ");
		}
		out.println();
		out.close();
	}
}


import java.util.Scanner;

/**
 * Created by first on 7/15/2018.
 */
public class AlyonaAndMex_A {
    public static void main (String [] args) {
        Scanner s = new Scanner(System.in);
        int size = s.nextInt();
        int numOfSubArrays = s.nextInt();
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < numOfSubArrays; i++){
            int left = s.nextInt();
            int right = s.nextInt();
            if(right - left + 1 < min){
                min = right - left + 1;
            }
        }
        int num = 0;
        System.out.println(min);
        for(int i = 0; i < size; i++){
            System.out.print(num + " ");
            num++;
            if(num == min){
                num = 0;
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int n = nextInt();
		int m = nextInt();
		int[]L = new int[m+1], R = new int[m+1];
		int min = n+1;
		for (int i = 1; i <= m; i++) {
			L[i] = nextInt();
			R[i] = nextInt();
			min = Math.min(min, R[i]-L[i]+1);
		}
		pw.println(min);
		int[]a = new int[n+1];
		int cur = 0;
		for (int i = 1; i <= n; i++) {
			a[i] = cur;
			cur++;
			if (cur==min)
				cur = 0;
		}
		for (int i = 1; i <= n; i++) {
			pw.print(a[i]+" ");
		}
		pw.close();
	}
	private static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	private static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	private static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	private static String next() throws IOException {
		while (st==null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}
}


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

public class Solution {

    static MyScanner sc;
    private static PrintWriter out;
    static long M2 = 1_000_000_000L + 7;

    private static HashMap<Long, Long>[] mods;

    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();
        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }

        out = new PrintWriter(new OutputStreamWriter(System.out));

        initData();
        solve();
        out.flush();
    }

    private static void initData() {

    }

    private static void solve() throws IOException {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] d1 = new int[m][2];
        int min = n;

        for (int i = 0; i < m; i++) {
            d1[i][0] = sc.nextInt() - 1;
            d1[i][1] = sc.nextInt() - 1;
            min = Math.min(min, d1[i][1] - d1[i][0] + 1);
        }

        out.println(min);
        for (int i = 0 ; i < n; i++) {
            out.print((i % min) + " ");
        }

    }

    private static boolean solve(int n, int p, int p1, int i) {
        return false;
    }

    private static boolean isset(long i, int k) {
        return (i & (1 << k)) > 0;
    }

    private static void solveT() throws IOException {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }

    private static long gcd(long l, long l1) {
        if (l > l1) return gcd(l1, l);
        if (l == 0) return l1;
        return gcd(l1 % l, l);
    }

    private static long pow(long a, long b, long m) {
        if (b == 0) return 1;
        if (b == 1) return a;
        long pp = pow(a, b / 2, m);
        pp *= pp;
        pp %= m;
        return (pp * (b % 2 == 0 ? 1 : a)) % m;
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

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

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        Integer[] nab(int n) {
            Integer[] k = new Integer[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

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

        int fi() {
            String t = next();
            int cur = 0;
            boolean n = t.charAt(0) == '-';
            for (int a = n ? 1 : 0; a < t.length(); a++) {
                cur = cur * 10 + t.charAt(a) - '0';
            }
            return n ? -cur : cur;
        }

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

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

}


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

public class TaskC {
  public static void main(String[] args) throws IOException {
    TaskC tC = new TaskC();
    PrintWriter out = new PrintWriter(System.out);
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    tC.solve(in, out);
    out.close();
  }

  int n, m;

  public void solve(BufferedReader in, PrintWriter out) throws IOException {
    String line = in.readLine();
    StringTokenizer st = new StringTokenizer(line);
    n = Integer.parseInt(st.nextToken());
    m = Integer.parseInt(st.nextToken());

    // input
    int minimumIntervalLength = Integer.MAX_VALUE;
    for (int i = 0; i < m; i++) {
      line = in.readLine();
      st = new StringTokenizer(line);
      int begin = Integer.parseInt(st.nextToken());
      int end = Integer.parseInt(st.nextToken());
      minimumIntervalLength = Math.min(minimumIntervalLength, end - begin + 1);
    }

    // process
    out.println(minimumIntervalLength);
    for (int i = 0; i < n; i++) {
      out.print((i % minimumIntervalLength) + " ");
    }
    out.println();
  }
}


import java.io.*;
import java.util.*;
public class div381C
{
	BufferedReader in;
	PrintWriter ob;
	StringTokenizer st;
	public static void main(String[] args) throws IOException {
		new div381C().run();
	}
	void run() throws IOException {
		//in=new BufferedReader(new FileReader("input.txt"));
		in=new BufferedReader(new InputStreamReader(System.in));
		ob=new PrintWriter(System.out);
		solve();
		ob.flush();
	}
	void solve() throws IOException {
		int n=ni();
		int a[]=new int[n+1];
		int m=ni();
		int b[][]=new int[m+1][2];
		int diff=Integer.MAX_VALUE;
		for(int i=1; i<=m ;i++) {
			int l=b[i][0]=ni();
			int r=b[i][1]=ni();
			int len=r-l+1;
			if(len<diff) {
				diff=len;
			}
		}
		ob.println(diff);
		int ans[]=new int[n+1];
		for(int i=0 ; i<m ; i++) {
			ans[i+1]=i%(diff);
		}
		for(int i=1 ; i<=m ; i++)
			ob.print(ans[i]+" ");
	}
	String ns() throws IOException {
		return nextToken();
	}
	long nl() throws IOException {
		return Long.parseLong(nextToken());
	}
	int ni() throws IOException {
		return Integer.parseInt(nextToken());
	}
	double nd() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextToken() throws IOException {
		if(st==null || !st.hasMoreTokens())
			st=new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int[] nia(int start,int b) throws IOException {
		int a[]=new int[b];
		for(int i=start;i<b;i++)
			a[i]=ni();
		return a;
	}
	long[] nla(int start,int n) throws IOException {
		long a[]=new long[n];
		for (int i=start; i<n ;i++ ) {
			a[i]=nl();
		}
		return a;
	}
}


import java.io.*;
import java.util.*;
public class div381C
{
	BufferedReader in;
	PrintWriter ob;
	StringTokenizer st;
	public static void main(String[] args) throws IOException {
		new div381C().run();
	}
	void run() throws IOException {
		//in=new BufferedReader(new FileReader("input.txt"));
		in=new BufferedReader(new InputStreamReader(System.in));
		ob=new PrintWriter(System.out);
		solve();
		ob.flush();
	}
	void solve() throws IOException {
		int n=ni();
		int a[]=new int[n+1];
		int m=ni();
		int b[][]=new int[m+1][2];
		int diff=Integer.MAX_VALUE;
		for(int i=1; i<=m ;i++) {
			int l=b[i][0]=ni();
			int r=b[i][1]=ni();
			int len=r-l;
			if(len<diff) {
				diff=len;
			}
		}
		int ans[]=new int[n+1];
		for(int i=0 ; i<m ; i++) {
			ans[i+1]=i%(diff);
		}
		for(int i=1 ; i<=m ; i++)
			ob.print(ans[i]+" ");
	}
	String ns() throws IOException {
		return nextToken();
	}
	long nl() throws IOException {
		return Long.parseLong(nextToken());
	}
	int ni() throws IOException {
		return Integer.parseInt(nextToken());
	}
	double nd() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextToken() throws IOException {
		if(st==null || !st.hasMoreTokens())
			st=new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int[] nia(int start,int b) throws IOException {
		int a[]=new int[b];
		for(int i=start;i<b;i++)
			a[i]=ni();
		return a;
	}
	long[] nla(int start,int n) throws IOException {
		long a[]=new long[n];
		for (int i=start; i<n ;i++ ) {
			a[i]=nl();
		}
		return a;
	}
}


import java.io.*;
import java.util.*;
public class div381C
{
	BufferedReader in;
	PrintWriter ob;
	StringTokenizer st;
	public static void main(String[] args) throws IOException {
		new div381C().run();
	}
	void run() throws IOException {
		//in=new BufferedReader(new FileReader("input.txt"));
		in=new BufferedReader(new InputStreamReader(System.in));
		ob=new PrintWriter(System.out);
		solve();
		ob.flush();
	}
	void solve() throws IOException {
		int n=ni();
		int a[]=new int[n+1];
		int m=ni();
		int b[][]=new int[m+1][2];
		int diff=Integer.MAX_VALUE;
		for(int i=1; i<=m ;i++) {
			int l=b[i][0]=ni();
			int r=b[i][1]=ni();
			int len=r-l+1;
			if(len<diff) {
				diff=len;
			}
		}
		ob.println(diff);
		int ans[]=new int[n+1];
		for(int i=0 ; i<n ; i++) {
			ans[i+1]=i%(diff);
		}
		for(int i=1 ; i<=n ; i++)
			ob.print(ans[i]+" ");
	}
	String ns() throws IOException {
		return nextToken();
	}
	long nl() throws IOException {
		return Long.parseLong(nextToken());
	}
	int ni() throws IOException {
		return Integer.parseInt(nextToken());
	}
	double nd() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextToken() throws IOException {
		if(st==null || !st.hasMoreTokens())
			st=new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int[] nia(int start,int b) throws IOException {
		int a[]=new int[b];
		for(int i=start;i<b;i++)
			a[i]=ni();
		return a;
	}
	long[] nla(int start,int n) throws IOException {
		long a[]=new long[n];
		for (int i=start; i<n ;i++ ) {
			a[i]=nl();
		}
		return a;
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main1 {

	static FastReader input = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);
	static final char REMOVED = 'R';

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

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

		PriorityQueue<Pair> pq = new PriorityQueue<>();

		for (int i = 0; i < m; i++) {
			int l = input.nextInt();
			int r = input.nextInt();
			pq.add(new Pair(l, r));
		}

		Pair x = pq.poll();

		int mex = x.y - x.x + 1;
		int a[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = i % mex;
		}
		out.println(mex);
		for (int i = 0; i < n; i++) {
			out.print(a[i] + " ");
		}

		out.flush();
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

		int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			String str = "";
			str = br.readLine();
			return str;
		}
	}

	static class con {
		static int IINF = (int) 1e9;
		static int _IINF = (int) -1e9;
		static long LINF = (long) 1e15;
		static long _LINF = (long) -1e15;
		static double EPS = 1e-9;
	}

	static class Triple implements Comparable<Triple> {
		int x;
		int y;
		int z;

		Triple(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		@Override
		public int compareTo(Triple o) {
			if (x == o.x && y == o.y)
				return z - o.z;
			if (x == o.x)
				return y - o.y;
			return x - o.x;
		}
	}

	static class Pair implements Comparable<Pair> {
		int x;
		int y;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;

		}

		@Override
		public int compareTo(Pair o) {
			return (y - x) - (o.y - o.x);
		}
	}

	static void shuffle(int[] a) {
		for (int i = 0; i < a.length; i++) {
			int r = i + (int) (Math.random() * (a.length - i));
			int tmp = a[r];
			a[r] = a[i];
			a[i] = tmp;
		}
	}

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

}


// package ArraysAndSearching;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class AlyonaNadMEx {
    public static void main(String[] args)throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String line[]=br.readLine().split(" ");
        int n=Integer.parseInt(line[0]);
        int m=Integer.parseInt(line[1]);
        int min=Integer.MAX_VALUE;
        int l=-1,r=-1;
        for(int i=1;i<=m;i++){
            line=br.readLine().split(" ");
            int x=Integer.parseInt(line[0]);
            int y=Integer.parseInt(line[1]);
            if(y-x+1<min){
                min=y-x+1;
                l=x;
                r=y;
            }
        }
        int k=0;
        int a[]=new int[n+1];
        for(int i=l;i<=r;i++){
            a[i]=k++;
        }
        k=0;
        for(int i=r+1;i<=n;i++){
            a[i]=k%min;
            k++;
        }
        k=min-1;
        for(int i=l-1;i>=0;i--){
            a[i]=k;
            k--;
            if(k<0){
                k=min-1;
            }
        }
        StringBuilder print=new StringBuilder();
        for(int i=1;i<=n;i++){
            print.append(a[i]+" ");
        }
        System.out.println(min);
        System.out.println(print.toString());
    }
}


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

public class mex {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt(), m = in.nextInt();
		int l, r;
		int ans = n;

		for (int i=0; i<m; ++i) {
			l = in.nextInt();
			r = in.nextInt();
			ans = Math.min(ans, r-l+1);
		}

		out.println(ans);
		for (int i=0; i<n; ++i)
			out.print((i%ans) + " ");
		out.println();
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		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 int nextInt() {
		return Integer.parseInt(next());
	}

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Random;
import java.util.StringTokenizer;

public class A {
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        FastScanner sc = new FastScanner();

        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] arr = new long[n];
        Interval[] intervals = new Interval[m];
        int minLength = n + 1;
        Interval minInterval = new Interval(0, n-1);
        for (int i = 0; i < m; i++) {
            int left = sc.nextInt() - 1;
            int right = sc.nextInt() - 1;
            intervals[i] = new Interval(left, right);
            int length = right - left + 1;
            if (length < minLength) {
                minLength = length;
                minInterval = intervals[i];
            }
        }

        int idx = minInterval.left;
        int num = 0;
        for (int i = idx; i < n; i++) {
            arr[i] = num;
            num = (num + 1) % minLength;
        }
        num = 0;
        for (int i = idx; i >= 0; i--) {
            arr[i] = num;
            num = Math.floorMod(num - 1, minLength);
        }
//        for (int i = 0; i < n; i++) {
//            int num = i % minLength;
//            arr[idx] = num;
//            idx = (idx + 1) % n;
//        }

        System.out.println(minLength);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            if (i > 0) sb.append(' ');
            sb.append(arr[i]);
        }
        System.out.println(sb);
    }

    static class Interval {
        final int left, right;

        public Interval(int left, int right) {
            this.left = left;
            this.right = right;
        }
    }

    static void shuffle(int[] arr) {
        Random rng = new Random();
        int length = arr.length;
        for (int idx = 0; idx < arr.length; idx++) {
            int toSwap = idx + rng.nextInt(length-idx);
            int tmp = arr[idx];
            arr[idx] = arr[toSwap];
            arr[toSwap] = tmp;
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        public FastScanner() {
            this(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 readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
        long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextLong();
            }
            return a;
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class dirty {

	public static void main(String[] args) throws IOException {
		BufferedReader tec=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out=new PrintWriter(System.out);
		StringTokenizer st=new StringTokenizer(tec.readLine());
		int x=Integer.parseInt(st.nextToken());
		int y=Integer.parseInt(st.nextToken());
		long min=Long.MAX_VALUE;
		for (int i = 0; i < y; i++) {
			st=new StringTokenizer(tec.readLine());
			min=Math.min(min, Math.abs(Long.parseLong(st.nextToken())-Long.parseLong(st.nextToken()))+1);
		}
		out.println(min);
		for (int i = 0; i < x; i++) {
			out.print(i%min);
			if(i!=x-1)
				out.print(" ");
		}
		out.println();
		out.close();
	}
}


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

public class Main {
	static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[(int) (2e5+10)]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static Reader sc = new Reader();

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

		int n = sc.nextInt();
		int m = sc.nextInt();
		int min = n;
		for(int i=0;i<m;++i) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			min = Math.min(min, r-l+1);
		}
		out.println(min);
		for(int i=0;i<n;++i) {
			out.print(i%min+" ");
		}

		out.close();
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int m = in.readInt();
            int minLength = n;
            for (int i = 0; i < m; i++) {
                int l = in.readInt();
                int r = in.readInt();
                minLength = Math.min(minLength, r - l + 1);
            }
            out.printLine(minLength);
            int[] result = new int[n];
            for (int i = 0; i < n; i++) {
                result[i] = i % minLength;
            }
            out.printLine(result);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(int[] array) {
            for (int i = 0; i < array.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(array[i]);
            }
        }

        public void printLine(int[] array) {
            print(array);
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void printLine(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

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

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.util.*;
public class Solution{
    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 j=in.nextInt();
            int k=in.nextInt();
            ans=k-j+1;
            if(min<and) min=ans;
        }
        System.out.println(min);
        for(int i=0;i<n;i++){
            System.out.print((i%min) +" ")
        }
    }
}


import java.util.*;
public class Solution{
    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 j=in.nextInt();
            int k=in.nextInt();
            int ans=k-j+1;
            if(min<ans) min=ans;
        }
        System.out.println(min);
        for(int i=0;i<n;i++){
            System.out.print((i%min) +" ");
        }
    }
}


import java.util.*;
public class Solution{
    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 j=in.nextInt();
            int k=in.nextInt();
            int ans=k-j+1;
            if(min<and) min=ans;
        }
        System.out.println(min);
        for(int i=0;i<n;i++){
            System.out.print((i%min) +" ");
        }
    }
}


import java.util.*;
public class Solution{
    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 j=in.nextInt();
            int k=in.nextInt();
            ans=k-j+1;
            if(min<and) min=ans;
        }
        System.out.println(min);
        for(int i=0;i<n;i++){
            System.out.print((i%min) +" ");
        }
    }
}


import java.util.*;
public class Solution{
    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 j=in.nextInt();
            int k=in.nextInt();
            int ans=k-j+1;
            if(ans<min) min=ans;
        }
        System.out.println(min);
        for(int i=0;i<n;i++){
            System.out.print((i%min) +" ");
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int len = Integer.MAX_VALUE;
            for (int i = 0; i < m; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                len = Math.min(len, r - l + 1);
            }
            out.println(len);
            for (int i = 0; i < n; i++) {
                out.print((i % len) + " ");
            }
        }

    }

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

        public InputReader(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream));
        }

        private void fillTokenizer() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }

        public String next() {
            fillTokenizer();
            return tokenizer.nextToken();
        }

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

    }
}


/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		MyScanner sc = new MyScanner();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int arr[] = new int[n];
		int len = 2000000000;
		for (int i = 0; i < m; ++i){
			int l = sc.nextInt();
			int r = sc.nextInt();
			len = Math.min(len, r - l + 1);
		}
		int k = 0;
		System.out.println(len);
		for (int i = 0; i < n; ++i){
			System.out.print(k + " ");
			k = (k + 1) % len;
		}
	}

	    //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         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;

/**
 * Created by akshaysharma on 10/01/17.
 */
public class Problem739A {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k,j,temp;
        int m = sc.nextInt();
        int count = Integer.MAX_VALUE;
        for(int i=0;i<m;i++){
            j = sc.nextInt();
            k = sc.nextInt();
            temp = k-j+1;
            count = Math.min(count,temp);
        }
        temp = 0;
        System.out.println(count);
        for(int i=0;i<n;i++){
            System.out.print(temp+" ");
            temp = (temp+1)%count;
        }
    }
}


import java.util.Scanner;

/**
 *
 * @author arabtech
 */
public class AlyonaAndMex2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int diff=100000000;
        int counter=0;
        for(int i=0;i<m;i++){
            int l=sc.nextInt();
            int r=sc.nextInt();
            int d=r-l;
            if(d<diff){
                diff=d;
            }
        }
        System.out.println(diff+1);
        for(int i=0;i<n;i++){
            if(counter>diff){
                counter=0;
            }
            if(i==n-1){
                System.out.print(counter);
            }
            else{
            System.out.print(counter+" ");
            }
            counter++;
        }
    }

}


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

public class CF_739A {
	public static void main(String[] args) {
		new CF_739A().run();
	}
	public void run(){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		int[] a = new int[n];
		int m = sc.nextInt();

		int min = Integer.MAX_VALUE;
		for(int i = 0;i<m;i++){
			int l = sc.nextInt()-1;
			int r = sc.nextInt()-1;
			min = Math.min(min, r-l+1);
			int index = 0;
			for(int j = l;j<=r;j++){
				a[j] = index++;
			}
		}
		out.println(min);
		for(int i = 0;i<n-1;i++){
			out.print(a[i] + " ");
		}
		out.println(a[n-1]);
		out.close();
	}
}
class FastScanner {
	public BufferedReader br;
	public StringTokenizer st;

	public FastScanner(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public boolean hasMoreTokens() {
		while (st == null || !st.hasMoreTokens()) {
			String line = null;
			try {
				line = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (line == null)
				return false;
			st = new StringTokenizer(line);
		}
		return true;
	}

	public String next() {
		if (!hasMoreTokens())
			return null;
		return st.nextToken();
	}

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

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

	//读一个int类型的数组
	public int[] readIntArray(int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = nextInt();
		}
		return array;
	}

	//读一个long数组
	public long[] readLongArray(int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = nextLong();
		}
		return array;
	}

	//读一个字符串数组
	public String[] readStringArray(int n) {
		String[] a = new String[n];
		for (int i = 0; i < n; i++) {
			a[i] = next();
		}
		return a;
	}

	//打乱一个数组，便于排序
	public void shuffleIntArray(int[] a) {
		Random rand = new Random();
		for (int i = 0; i < a.length; i++) {
			int x = rand.nextInt(i + 1); // 0~i
			int t = a[i];
			a[i] = a[x];
			a[x] = t;
		}
	}

	// 只适合比较小的数，太大的数会越界
	public long factorial(long n) {
		if (n == 0)
			return 1L;
		long res = 1;
		for (long i = 2; i <= n; i++) {
			res *= i;
		}
		return res;
	}

	// 只适合比较小的数，太大的数会越界
	public long combination(long mom, long son) {
		return factorial(mom) / (factorial(son) * factorial(mom - son));
	}

	//求最小公倍数
	public long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	//求最大公约数
	public long lcm(long a, long b) {
		return a * b / (gcd(a, b));
	}

	//格式化double类型的数
	public double format(String pattern, double d) {
		DecimalFormat df = new DecimalFormat(pattern);
		return Double.parseDouble(df.format(d));
	}

	//判断一个数是否是2的指数
	public boolean isPowerOfTwo(long v) {
		return (v & (v - 1)) == 0;
	}
}


import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
public class CF_739A {
	public static void main(String[] args) {
		new CF_739A().run();
	}
	public void run(){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		int[] a = new int[n];
		int m = sc.nextInt();

		int min = Integer.MAX_VALUE;
		for(int i = 0;i<m;i++){
			int l = sc.nextInt()-1;
			int r = sc.nextInt()-1;
			min = Math.min(min, r-l+1);
		}
		out.println(min);
		int cur = 0;
		for(int i = 0;i<n-1;i++){
			out.print(cur%min + " ");
			cur++;
		}
		out.println(cur%min);
		out.close();
	}
}

class FastScanner {
	public BufferedReader br;
	public StringTokenizer st;

	public FastScanner(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

	public boolean hasMoreTokens() {
		while (st == null || !st.hasMoreTokens()) {
			String line = null;
			try {
				line = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (line == null)
				return false;
			st = new StringTokenizer(line);
		}
		return true;
	}

	public String next() {
		if (!hasMoreTokens())
			return null;
		return st.nextToken();
	}

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

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

	//读一个int类型的数组
	public int[] readIntArray(int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = nextInt();
		}
		return array;
	}

	//读一个long数组
	public long[] readLongArray(int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = nextLong();
		}
		return array;
	}

	//读一个字符串数组
	public String[] readStringArray(int n) {
		String[] a = new String[n];
		for (int i = 0; i < n; i++) {
			a[i] = next();
		}
		return a;
	}

	//打乱一个数组，便于排序
	public void shuffleIntArray(int[] a) {
		Random rand = new Random();
		for (int i = 0; i < a.length; i++) {
			int x = rand.nextInt(i + 1); // 0~i
			int t = a[i];
			a[i] = a[x];
			a[x] = t;
		}
	}

	// 只适合比较小的数，太大的数会越界
	public long factorial(long n) {
		if (n == 0)
			return 1L;
		long res = 1;
		for (long i = 2; i <= n; i++) {
			res *= i;
		}
		return res;
	}

	// 只适合比较小的数，太大的数会越界
	public long combination(long mom, long son) {
		return factorial(mom) / (factorial(son) * factorial(mom - son));
	}

	//求最小公倍数
	public long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	//求最大公约数
	public long lcm(long a, long b) {
		return a * b / (gcd(a, b));
	}

	//格式化double类型的数
	public double format(String pattern, double d) {
		DecimalFormat df = new DecimalFormat(pattern);
		return Double.parseDouble(df.format(d));
	}

	//判断一个数是否是2的指数
	public boolean isPowerOfTwo(long v) {
		return (v & (v - 1)) == 0;
	}
}


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 + " ");
        }
    }
}