import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class SolutionE extends Thread {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    private static final FastReader scanner = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);

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

    public void run() {
        int t = 1;
        for (int i = 0; i < t; i++) {
            solve();
        }
        out.close();
    }

    private static void solve() {
        int n = scanner.nextInt();
        int p = scanner.nextInt();
        Integer[] a = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Arrays.sort(a);

        int minXForWin = 0;
        for (int i = 0; i < n; i++) {
            minXForWin = Math.max(minXForWin, a[i] - i);
        }

        int low = minXForWin;
        int high = 1_200_000_000;

        while (high - low > 1) {
            int mid = (low + high) / 2; //start Candies

            int amountCandies = mid;
            int amountEnemiesDefeated = 0;
            boolean isGood = amountCandies < a[n-1];
            for (int i = 0; i < n; i++) {
                if (a[i] > amountCandies && i - amountEnemiesDefeated >= p) {
                    isGood = false;
                } else if (a[i] > amountCandies) {
                    amountEnemiesDefeated++;
                    amountCandies++;
                }
            }

            if (isGood) {
                low = mid;
            } else {
                high = mid;
            }
        }
        System.out.println(Math.max(0, high - minXForWin));
        System.out.println(IntStream.range(minXForWin, high).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class SolutionE extends Thread {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    private static final FastReader scanner = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);

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

    public void run() {
        int t = 1;
        for (int i = 0; i < t; i++) {
            solve();
        }
        out.close();
    }

    private static void solve() {
        int n = scanner.nextInt();
        int p = scanner.nextInt();
        Integer[] a = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Arrays.sort(a);

        int minXForWin = 0;
        for (int i = 0; i < n; i++) {
            minXForWin = Math.max(minXForWin, a[i] - i);
        }

        int low = minXForWin - 1;
        int high = 1_100_000_001;

        while (high - low > 1) {
            int mid = (low + high) / 2; //start Candies

            int amountCandies = mid;
            int amountEnemiesDefeated = 0;
            boolean isGood = amountCandies < a[n-1];
            for (int i = 0; i < n; i++) {
                if (a[i] > amountCandies && i - amountEnemiesDefeated >= p) {
                    isGood = false;
                } else if (a[i] > amountCandies) {
                    amountEnemiesDefeated++;
                    amountCandies++;
                }
            }

            if (isGood) {
                low = mid;
            } else {
                high = mid;
            }
        }
        System.out.println(Math.max(0, high - minXForWin));
        System.out.println(IntStream.range(minXForWin, high).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
    }
}


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

public class Main {
    static PrintWriter out;
    static Reader in;
    public static void main(String[] args) throws IOException {
        //out = new PrintWriter(new File("out.txt"));
        //PrintWriter out = new PrintWriter(System.out);
        //in = new Reader(new FileInputStream("in.txt"));
        //Reader in = new Reader();
        input_output();
        Main solver = new Main();
        solver.solve();
        out.flush();
        out.close();

    }

    static int INF = (int)1e9+5;
    static int maxn = (int)2e6+5;
    static int mod=(int)1e9+7 ;
    static int n, m, t, q, k;

    void solve() throws IOException{
        n = in.nextInt();
        int p = in.nextInt();

        int max = 0, min = INF;
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            min = Math.min(min, arr[i]);
            max = Math.max(max, arr[i]);
        }
        min = max-n+1;

        boolean flag = false;
        Map<Integer, Integer> cnt = new HashMap<>();
        for (int i = 0; i < n; i++) cnt.put(arr[i], cnt.getOrDefault(arr[i], 0)+1);

        long[] sum = new long[max-min+10];
        long last = 0;
        long maxdif = -1;

        for (int i = 0; i < n; i++) if (arr[i] <= min) sum[0]++;
        for (int i = min+1; i <= max; i++) {
            sum[i-min] = sum[i-min-1]+cnt.getOrDefault(i, 0)-1;
            maxdif = Math.max(maxdif, -sum[i-min]);
        }
        maxdif++;
        min+=maxdif;

        Map<Integer, Integer> exists = new HashMap<>();

        sum[0] = 0;
        for (int i = 0; i < n; i++) if (arr[i] <= min) sum[0]++;
        for (int i = min+1; i <= max; i++) sum[i-min] = sum[i-min-1]+cnt.getOrDefault(i, 0)-1;
        last = sum[max-min];

        for (int i = min ; i <= max; i++) {
            sum[i-min]%=p;
            exists.put((int)sum[i-min], exists.getOrDefault((int)sum[i-min], 0)+1);
        }
        int ans = 0;
        ArrayList<Integer> list = new ArrayList<>();

        int tmp = 0;
        for (int i = min; i <= max; i++) {
            tmp = (10000*p-(i-min))%p;
            if(i != min) exists.put((int)sum[i-min-1], exists.getOrDefault((int)sum[i-min-1], 1)-1);
            if (exists.getOrDefault(tmp, 0) == 0 && last+(i-min) < p) {
                ans++;
                list.add(i);
            }
        }

        out.println(ans);
        for (int i = 0; i < list.size(); i++) {
            out.print(list.get(i)+" ");
        }
        out.println();
    }

    //<>

    static class Reader {

        private InputStream mIs;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public Reader() {
            this(System.in);
        }

        public Reader(InputStream is) {
            mIs = is;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();

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

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

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

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long 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 int nextInt() {
            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) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }
    static void input_output() throws IOException {
        File f = new File("in.txt");
        if(f.exists() && !f.isDirectory()) {
            in = new Reader(new FileInputStream("in.txt"));
        } else in = new Reader();
        f = new File("out.txt");
        if(f.exists() && !f.isDirectory()) {
            out = new PrintWriter(new File("out.txt"));
        } else out = new PrintWriter(System.out);
    }
}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		long i = 0;
		for(long val : list){
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[(int)i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - ((int)i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	minx = Math.max(0,mx-(n-1));
    	maxx = 0; int ix = 0;
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	if(x<(arr[ix]-ix)){
        		continue;
        	}
        	set.add(x);
        	maxx = x;
        	minx = Math.min(minx,x);
        }
        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        // out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		long i = 0;
		for(long val : list){
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[(int)i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - ((int)i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	minx = Math.max(0,mx-(n-1));
    	maxx = 0; int ix = 0;
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	if(x<(arr[ix]-ix)){
        		continue;
        	}
        	set.add(x);
        	maxx = x;
        	minx = Math.min(minx,x);
        }
        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		long i = 0;
		for(long val : list){
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[(int)i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - ((int)i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	minx = Math.max(0,mx-(n-1));
    	maxx = 0; int ix = 0;
    	int minVal[] = new int[n];
    	int v = mx;
    	for(int i=n-1;i>=0;i--){
    		v = Math.max(v,arr[i]);
    		minVal[i] = v;
    		v--;
    	}
    	// out.println("minVal[0]: "+minVal[0]);
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	if(x<minVal[0]){
        		continue;
        	}
        	set.add(x);
        	maxx = x;
        	minx = Math.min(minx,x);
        }

        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        // out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        // out.println(-1%223);
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		long i = 0;
		for(long val : list){
			if((val-i)<=0){
				set = new HashSet<Integer>();
				return;
			}
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[(int)i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - ((int)i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	minx = Math.max(0,mx-(n-1));
    	maxx = 0; int ix = 0;
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	if(x<(arr[ix]-ix)){
        		continue;
        	}
        	set.add(x);
        	maxx = x;
        	minx = Math.min(minx,x);
        }

        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        // out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        // out.println(-1%223);
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		long i = 0;
		for(long val : list){
			if((val-i)<=0){
				set = new HashSet<Integer>();
				return;
			}
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[(int)i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - ((int)i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	minx = Math.max(0,mx-(n-1));
    	maxx = 0; int ix = 0;
    	int minVal[] = new int[n];
    	int v = mx;
    	for(int i=n-1;i>=0;i--){
    		v = Math.max(v,arr[i]);
    		minVal[i] = v;
    		v--;
    	}
    	// out.println("minVal[0]: "+minVal[0]);
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	if(x<minVal[0]){
        		continue;
        	}
        	set.add(x);
        	maxx = x;
        	minx = Math.min(minx,x);
        }

        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        // out.println(-1%223);
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			int ct = arr.length - (arr[i]-x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		int i = 0;
		for(int val : list){
			parr[(val-i)%p]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - (i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	minx = Math.max(0,mx-(n-1));
    	maxx = 0; int ix = 0;
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	set.add(x);
        	maxx = x;
        }
        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        // out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		long i = 0;
		for(long val : list){
			if((val-i)<=0){
				set = new HashSet<Integer>();
				return;
			}
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[(int)i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - ((int)i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	minx = Math.max(0,mx-(n-1));
    	maxx = 0; int ix = 0;
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	if(x<(arr[ix]-ix)){
        		continue;
        	}
        	set.add(x);
        	maxx = x;
        	minx = Math.min(minx,x);
        }
        if(maxx!=(mx-1)){
        	out.println("FUCK "+ maxx);
        }
        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        // out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        // out.println(-1%223);
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		long i = 0;
		for(long val : list){
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[(int)i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - ((int)i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	minx = Math.max(0,mx-(n-1));
    	maxx = 0; int ix = 0;
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	if(x<(arr[ix]-ix)){
        		continue;
        	}
        	set.add(x);
        	maxx = x;
        	minx = Math.min(minx,x);
        }
        if(maxx!=(mx-1)){
        	out.println("FUCK");
        }
        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        // out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        // out.println(-1%223);
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		long i = 0;
		for(long val : list){
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - (i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	minx = Math.max(0,mx-(n-1));
    	maxx = 0; int ix = 0;
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	set.add(x);
        	maxx = x;
        }
        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        // out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		long i = 0;
		for(long val : list){
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[(int)i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - ((int)i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	minx = Math.max(0,mx-(n-1));
    	maxx = 0; int ix = 0;
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	set.add(x);
        	maxx = x;
        }
        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        // out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		long i = 0;
		for(long val : list){
			if((val-i)<=0){
				set = new HashSet<Integer>();
				return;
			}
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[(int)i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - ((int)i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	minx = Math.max(0,mx-(n-1));
    	maxx = 0; int ix = 0;
    	int minVal[] = new int[n];
    	int v = mx;
    	for(int i=n-1;i>=0;i--){
    		v = Math.max(v,arr[i]);
    		minVal[i] = v;
    		v--;
    	}
    	// out.println("minVal[0]: "+minVal[0]);
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	if(x<minVal[0]){
        		continue;
        	}
        	set.add(x);
        	maxx = x;
        	minx = Math.min(minx,x);
        }

        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        // out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        // out.println(-1%223);
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		// int less = 0;
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		// out.println("list : "+list);
		long i = 0;
		for(long val : list){
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}
		// int ct = maxx - minx + 1;
		for(i=0;i<p;i++){
			if(parr[(int)i]!=0){
				// out.println("i "+i);
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - ((int)i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
		// return true;
	}
	// public static boolean valid(int x, int arr[]){
	// 	ArrayList<Integer> list=  new ArrayList<Integer>();
	// 	for(int i=arr.length-1;i>=0;i--){
	// 		if(arr[i]<=x){
	// 			less++;
	// 		}
	// 		else{
	// 			int ct = arr.length - (arr[i]-x);
	// 			list.add(ct);
	// 		}
	// 	}
	// 	if(p<=less)
	// 		return false;
	// 	Collections.sort(list);
	// 	int i = 0;
	// 	for(int val : list){
	// 		if((val-i)<=0 || (val-i)%p==0)
	// 			return false;
	// 		i++;
	// 	}
	// 	return true;
	// }
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	// ArrayList<Integer> ansList = new ArrayList<Integer>();
    	int less = 0;
    	maxx = 0; int ix = 0;
    	minx = mx;
    	for(int i=n-1;i>=0;i--){
    		minx = Math.max(minx,arr[i]);
    		if(i!=0)
    			minx--;
    	}
    	// out.println("minVal[0]: "+minVal[0]);
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	set.add(x);
        	maxx = x;
        	minx = Math.min(minx,x);
        }

        // out.println("set : "+set);
        if(maxx==0 || arr[0]==mx)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        // out.println("set: "+set);
        // out.println(minx+" "+maxx);
        // for(int x = maxx; x>=minx; x--){
        // 	if(valid(x,arr)){
        // 		sub(x,arr,set);
        // 	}
        // }
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        // out.println(-1%223);
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


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

public class e1 {
	public static PrintWriter out;
	public static InputReader in;
	public static int minx,maxx;
	public static void sub(int x, int arr[], int p, HashSet<Integer> set){
		ArrayList<Long> list = new ArrayList<Long>();
		int parr[] = new int[p];
		Arrays.fill(parr,0);
		for(int i=arr.length-1;i>=0;i--){
			if(arr[i]<=x)
				break;
			long ct = (long)arr.length - (long)((long)arr[i]-(long)x);
			list.add(ct);
		}
		Collections.sort(list);
		long i = 0;
		for(long val : list){
			parr[(int)((val-i)%((long)p))]++;
			i++;
		}

		for(i=0;i<p;i++){
			if(parr[(int)i]!=0){
				if(i==0){
					set.remove(maxx);
				}
				int val = maxx - ((int)i);
				while(val>=minx){
					set.remove(val);
					val-=p;
				}
			}
		}
	}
	public static void main(String[] args)throws IOException {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);
        int n = in.nextInt();
        int p = in.nextInt();
        int arr[] = new int[n];
        HashSet<Integer> set = new HashSet<Integer>();
        int mx = -1;
        for(int i=0;i<n;i++){
        	arr[i]=in.nextInt();
        	mx = Math.max(arr[i],mx);
        }
        mergesort(arr,0,n-1);
    	int less = 0;
    	maxx = -1;
    	minx = mx;
    	for(int i=n-1;i>=0;i--){
    		minx = Math.max(minx,arr[i]);
    		if(i!=0)
    			minx--;
    	}
    	int ix = 0;
        for(int x=minx;x<=mx-1;x++){
        	while(ix<n && arr[ix]<=x){
        		ix++;
        	}
        	if(ix>=p){
        		break;
        	}
        	set.add(x);
        	maxx = x;
        	minx = Math.min(minx,x);
        }
        if(maxx==-1)
        {
        	out.println(0);
        	out.close();
        	return;
        }
        sub(maxx,arr,p,set);
        out.println(set.size());
        ArrayList<Integer> list = new ArrayList<Integer>(set);
        Collections.sort(list);
        for(int x : list){
        	out.print(x+" ");
        }
        out.println();
        out.close();
	}
	public static void merge(int[] arr, int first,int mid,int last){

		int a[]=new int[mid-first+1];

		int b[]=new int[last-mid];

		// int c[]=new int[mid-first+1];

		// int d[]=new int[last-mid];

		int pahela,dusra;
		pahela=dusra=0;

		for(pahela=0;pahela<mid-first+1;pahela++)
		{
			a[pahela]=arr[first+pahela];
			// c[pahela]=indexes[first+pahela];
		}

		for(dusra=0;dusra<last-mid;dusra++)
		{
			b[dusra]=arr[mid+1+dusra];
			// d[dusra]=indexes[mid+1+dusra];
		}

		pahela=0;
		dusra=0;
		int maha=first;

		while(pahela<mid-first+1 && dusra<last-mid)
		{
			if(a[pahela]<=b[dusra])
			{
				arr[maha]=a[pahela];
				// indexes[maha]=c[pahela];
				maha++;
				pahela++;
			}

			else
			{
				arr[maha]=b[dusra];
				// indexes[maha]=d[dusra];
				maha++;
				dusra++;
			}
		}

		while(pahela<mid-first+1)
		{
			arr[maha]=a[pahela];
			// indexes[maha]=c[pahela];
			maha++;
			pahela++;
		}

		while(dusra<last-mid){
			arr[maha]=b[dusra];
			// indexes[maha]=d[dusra];
			maha++;
			dusra++;
		}
	}
	public static void mergesort(int arr[],int first,int last)
	{
		if(first < last) {
		int mid=(first+last)/2;
		mergesort(arr,first,mid);
		mergesort(arr,mid+1,last);
		merge(arr,first,mid,last);
	}
	}

    static 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());
        }

    }

}


// upsolve with kaiboy, coached by rainboy
import java.io.*;
import java.util.*;

public class CF1371E2 extends PrintWriter {
	CF1371E2() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1371E2 o = new CF1371E2(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int md = sc.nextInt();
		int[] aa = new int[n];
		int a_ = 0;
		for (int i = 0; i < n; i++)
			a_ = Math.max(a_, aa[i] = sc.nextInt());
		int[] kk = new int[n];
		for (int i = 0; i < n; i++) {
			int d = a_ - aa[i];
			if (d < n)
				kk[d]++;
		}
		boolean[] bad = new boolean[n];
		int n_max = n, n_min = n, n_ = n;
		for (int d_ = 1; d_ < n; d_++) {
			n_ -= kk[d_ - 1];
			n_max = Math.max(n_max - 1, n_);
			n_min = Math.min(n_min - 1, n_);
			if (n_min <= 0 || n_max >= md)
				bad[d_] = true;
		}
		int cnt = 0;
		for (int d_ = 1; d_ < n; d_++)
			if (!bad[d_])
				cnt++;
		println(cnt);
		for (int d_ = n - 1; d_ >= 1; d_--)
			if (!bad[d_])
				print(a_ - d_ + " ");
		println();
	}
}


import java.util.ArrayList;
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;

public class AsterismHard {

    public static void main(String[] args){
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        int n = scan.nextInt();
        int p = scan.nextInt();
        int[] a = new int [n];
        int ans = 0;
        List<Integer> list = new ArrayList<Integer>();

        for (int i = 0;i < n;i++)
            a[i] = scan.nextInt();

        Arrays.sort(a);
        int mx = a[n-1],mn = mx - n + 1;
        int[] f = new int [n+n+10];
        for (int i = 0;i < n;i++)
            f[i] = 0;
        for (int i = 0;i < n;i++){
            if (a[i] <= mn) f[0]++;
            else f[a[i]-mn]++;
        }
        for (int i = 1;i < n;i++)
            f[i] += f[i-1];
        for (int i = n;i < n+n;i++)
            f[i] = f[i-1];
        Map<Integer,Integer> mp = new HashMap<Integer,Integer>();
        for (int i = 0;i < n+n;i++){
            int u = (p-f[i]%p+i) % p;
            // System.out.printf("%d*",u);
            if (mp.containsKey(u)){
                int val = mp.get(u);
                mp.put(u, val+1);
            }
            else mp.put(u, 1);

            if (i >= n-1){
                if (mp.containsKey((i-n+1) % p)){
                    int val = mp.get((i-n+1) % p);
                    if (val == 0) {
                       ans++;
                       list.add(i-n+1+mn);
                    }
                }
                else {
                    ans++;
                    list.add(i-n+1+mn);
                }
                int v = (p-f[i-n+1]%p+i-n+1) % p;
                if (mp.containsKey(v)){
                    int val = mp.get(v);
                    mp.put(v, val-1);
                }
            }
            if (i-n+1 >= n) break;
        }
        System.out.println(ans);
        for (int i = 0;i < list.size();i++){
            System.out.printf("%d ",list.get(i));
        }
        System.out.println();
        scan.close();
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

public class AsterismHard {

    public static void main(String[] args) throws Exception{
        StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        cin.nextToken();
        int n = (int) cin.nval;
        cin.nextToken();
        int p = (int) cin.nval;

        int[] a = new int [n];
        int ans = 0;
        List<Integer> list = new ArrayList<Integer>();

        for (int i = 0;i < n;i++){
            cin.nextToken();
            a[i] = (int) cin.nval;
        }

        Arrays.sort(a);
        int mx = a[n-1],mn = mx - n + 1;
        int[] f = new int [n+n+10];
        for (int i = 0;i < n;i++)
            f[i] = 0;
        for (int i = 0;i < n;i++){
            if (a[i] <= mn) f[0]++;
            else f[a[i]-mn]++;
        }
        for (int i = 1;i < n;i++)
            f[i] += f[i-1];
        for (int i = n;i < n+n;i++)
            f[i] = f[i-1];
        Map<Integer,Integer> mp = new HashMap<Integer,Integer>();
        for (int i = 0;i < n+n;i++){
            int u = (p-f[i]%p+i) % p;
            // System.out.printf("%d*",u);
            if (mp.containsKey(u)){
                int val = mp.get(u);
                mp.put(u, val+1);
            }
            else mp.put(u, 1);

            if (i >= n-1){
                if (mp.containsKey((i-n+1) % p)){
                    int val = mp.get((i-n+1) % p);
                    if (val == 0) {
                       ans++;
                       list.add(i-n+1+mn);
                    }
                }
                else {
                    ans++;
                    list.add(i-n+1+mn);
                }
                int v = (p-f[i-n+1]%p+i-n+1) % p;
                if (mp.containsKey(v)){
                    int val = mp.get(v);
                    mp.put(v, val-1);
                }
            }
            if (i-n+1 >= n) break;
        }
        System.out.println(ans);
        for (int i = 0;i < list.size();i++){
            System.out.printf("%d ",list.get(i));
        }
        System.out.println();
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class AsterismHard {

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int p = scan.nextInt();
        int[] a = new int [n];
        int ans = 0;
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0;i < n;i++)
            a[i] = scan.nextInt();
        Arrays.sort(a);
        int mx = a[n-1],mn = mx - n + 1;
        int[] f = new int [n+n+10];
        for (int i = 0;i < n;i++)
            f[i] = 0;
        for (int i = 0;i < n;i++){
            if (a[i] <= mn) f[0]++;
            else f[a[i]-mn]++;
        }
        for (int i = 1;i < n;i++)
            f[i] += f[i-1];
        for (int i = n;i < n+n;i++)
            f[i] = f[i-1];
        Map<Integer,Integer> mp = new HashMap<Integer,Integer>();
        for (int i = 0;i < n+n;i++){
            int u = (p-f[i]%p+i) % p;
            if (mp.containsKey(u)){
                mp.put(u, mp.get(u)+1);
            }
            else mp.put(u, 1);
            if (i >= n-1){
                if (mp.containsKey(i % p)){

                }
                else {
                    ans++;
                    list.add(i-n+1+mn);
                }
                int v = (p-f[i-n+1]%p+i-n+1) % p;
                if (mp.containsKey(v)){
                    int val = mp.get(v);
                    if (val == 1) mp.remove(v,val);
                    else mp.put(u, val-1);
                }
            }
            if (i-n+1 >= n) break;
        }
        System.out.println(ans);
        for (int i = 0;i < list.size();i++){
            System.out.printf("%d ",list.get(i));
        }
        System.out.println();
        scan.close();
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class AsterismHard {

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int p = scan.nextInt();
        int[] a = new int [n];
        int ans = 0;
        List<Integer> list = new ArrayList<Integer>();

        for (int i = 0;i < n;i++)
            a[i] = scan.nextInt();

        Arrays.sort(a);
        int mx = a[n-1],mn = mx - n + 1;
        int[] f = new int [n+n+10];
        for (int i = 0;i < n;i++)
            f[i] = 0;
        for (int i = 0;i < n;i++){
            if (a[i] <= mn) f[0]++;
            else f[a[i]-mn]++;
        }
        for (int i = 1;i < n;i++)
            f[i] += f[i-1];
        for (int i = n;i < n+n;i++)
            f[i] = f[i-1];
        Map<Integer,Integer> mp = new TreeMap<Integer,Integer>();
        for (int i = 0;i < n+n;i++){
            int u = (p-f[i]%p+i) % p;
            // System.out.printf("%d*",u);
            if (mp.containsKey(u)){
                int val = mp.get(u);
                mp.put(u, val+1);
            }
            else mp.put(u, 1);

            if (i >= n-1){
                if (mp.containsKey((i-n+1) % p)){
                    int val = mp.get((i-n+1) % p);
                    if (val == 0) {
                       ans++;
                       list.add(i-n+1+mn);
                    }
                }
                else {
                    ans++;
                    list.add(i-n+1+mn);
                }
                int v = (p-f[i-n+1]%p+i-n+1) % p;
                if (mp.containsKey(v)){
                    int val = mp.get(v);
                    mp.put(v, val-1);
                }
            }
            if (i-n+1 >= n) break;
        }
        System.out.println(ans);
        for (int i = 0;i < list.size();i++){
            System.out.printf("%d ",list.get(i));
        }
        System.out.println();
        scan.close();
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class AsterismHard {

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int p = scan.nextInt();
        int[] a = new int [n];
        int ans = 0;
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0;i < n;i++)
            a[i] = scan.nextInt();
        Arrays.sort(a);
        int mx = a[n-1],mn = mx - n + 1;
        int[] f = new int [n+n+10];
        for (int i = 0;i < n;i++)
            f[i] = 0;
        for (int i = 0;i < n;i++){
            if (a[i] <= mn) f[0]++;
            else f[a[i]-mn]++;
        }
        for (int i = 1;i < n;i++)
            f[i] += f[i-1];
        for (int i = n;i < n+n;i++)
            f[i] = f[i-1];
        Map<Integer,Integer> mp = new HashMap<Integer,Integer>();
        for (int i = 0;i < n+n;i++){
            int u = (p-f[i]%p+i) % p;
            // System.out.printf("%d*",u);
            if (mp.containsKey(u)){
                int val = mp.get(u);
                mp.put(u, val+1);
            }
            else mp.put(u, 1);

            if (i >= n-1){
                if (mp.containsKey((i-n+1) % p)){
                    int val = mp.get((i-n+1) % p);
                    if (val == 0) {
                       ans++;
                       list.add(i-n+1+mn);
                    }
                }
                else {
                    ans++;
                    list.add(i-n+1+mn);
                }
                int v = (p-f[i-n+1]%p+i-n+1) % p;
                if (mp.containsKey(v)){
                    int val = mp.get(v);
                    mp.put(v, val-1);
                }
            }
            if (i-n+1 >= n) break;
        }
        System.out.println(ans);
        for (int i = 0;i < list.size();i++){
            System.out.printf("%d ",list.get(i));
        }
        System.out.println();
        scan.close();
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

public class AsterismHard {

    public static void main(String[] args) throws Exception{
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        int n = scan.read();
        int p = scan.read();
        int[] a = new int [n];
        int ans = 0;
        List<Integer> list = new ArrayList<Integer>();

        for (int i = 0;i < n;i++)
            a[i] = scan.read();

        Arrays.sort(a);
        int mx = a[n-1],mn = mx - n + 1;
        int[] f = new int [n+n+10];
        for (int i = 0;i < n;i++)
            f[i] = 0;
        for (int i = 0;i < n;i++){
            if (a[i] <= mn) f[0]++;
            else f[a[i]-mn]++;
        }
        for (int i = 1;i < n;i++)
            f[i] += f[i-1];
        for (int i = n;i < n+n;i++)
            f[i] = f[i-1];
        Map<Integer,Integer> mp = new HashMap<Integer,Integer>();
        for (int i = 0;i < n+n;i++){
            int u = (p-f[i]%p+i) % p;
            // System.out.printf("%d*",u);
            if (mp.containsKey(u)){
                int val = mp.get(u);
                mp.put(u, val+1);
            }
            else mp.put(u, 1);

            if (i >= n-1){
                if (mp.containsKey((i-n+1) % p)){
                    int val = mp.get((i-n+1) % p);
                    if (val == 0) {
                       ans++;
                       list.add(i-n+1+mn);
                    }
                }
                else {
                    ans++;
                    list.add(i-n+1+mn);
                }
                int v = (p-f[i-n+1]%p+i-n+1) % p;
                if (mp.containsKey(v)){
                    int val = mp.get(v);
                    mp.put(v, val-1);
                }
            }
            if (i-n+1 >= n) break;
        }
        System.out.println(ans);
        for (int i = 0;i < list.size();i++){
            System.out.printf("%d ",list.get(i));
        }
        System.out.println();
        scan.close();
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E2AsterismHardVersion solver = new E2AsterismHardVersion();
        solver.solve(1, in, out);
        out.close();
    }

    static class E2AsterismHardVersion {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int n = sc.nextInt(), p = sc.nextInt();
            int[] arr = new int[n];
            int max = -1;
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
                max = Math.max(max, arr[i]);
            }
            shuffle(arr);
            Arrays.sort(arr);
            int low = bs(arr, max), high = max;
            int start = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (check(arr, mid, p)) {
                    high = mid - 1;
                    start = mid;
                } else
                    low = mid + 1;
            }
            int end = -1;
            if (start != -1) {
                low = start;
                high = max;
                while (low <= high) {
                    int mid = (low + high) / 2;
                    if (check(arr, mid, p)) {
                        low = mid + 1;
                        end = mid;
                    } else
                        high = mid - 1;
                }
            }
            if (start == -1) {
                pw.println(0);
                pw.println();
                return;
            }
            pw.println(end - start + 1);
            for (int i = start; i <= end; i++)
                pw.print(i + " ");
        }

        private void shuffle(int[] arr) {
            for (int i = 0; i < arr.length; i++) {
                int rand = (int) (Math.random() * (i + 1));
                int temp = arr[rand];
                arr[rand] = arr[i];
                arr[i] = temp;
            }
        }

        private boolean check2(int[] arr, int mid) {
            for (int i = 0; i < arr.length; i++) {
                int pos = find(arr, mid + i) + 1 - i;
                if (pos <= 0)
                    return false;
            }
            return true;
        }

        private boolean check(int[] arr, int mid, int p) {
            for (int i = 0; i < arr.length; i++) {
                if (find(arr, mid + i) == -1)
                    return false;
                int pos = find(arr, mid + i) + 1 - i;
                if (pos % p == 0)
                    return false;
            }
            return true;
        }

        private int find(int[] arr, int elem) {
            int low = 0, high = arr.length - 1;
            int toRet = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (arr[mid] <= elem) {
                    low = mid + 1;
                    toRet = mid;
                } else
                    high = mid - 1;
            }
            return toRet;
        }

        private int bs(int[] arr, int max) {
            int low = 1, high = max;
            int toRet = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (check2(arr, mid)) {
                    high = mid - 1;
                    toRet = high;
                } else
                    low = mid + 1;
            }
            return toRet;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E2AsterismHardVersion solver = new E2AsterismHardVersion();
        solver.solve(1, in, out);
        out.close();
    }

    static class E2AsterismHardVersion {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int n = sc.nextInt(), p = sc.nextInt();
            Integer[] arr = new Integer[n];
            int max = -1;
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
                max = Math.max(max, arr[i]);
            }
            Arrays.sort(arr);
            int low = bs(arr, max), high = max;
            int start = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (check(arr, mid, p)) {
                    high = mid - 1;
                    start = mid;
                } else
                    low = mid + 1;
            }
            int end = -1;
            if (start != -1) {
                low = start;
                high = max;
                while (low <= high) {
                    int mid = (low + high) / 2;
                    if (check(arr, mid, p)) {
                        low = mid + 1;
                        end = mid;
                    } else
                        high = mid - 1;
                }
            }
            if (start == -1) {
                pw.println(0);
                pw.println();
                return;
            }
            pw.println(end - start + 1);
            StringBuilder sb = new StringBuilder();
            for (int i = start; i <= end; i++)
                sb.append(i + " ");
            pw.println(sb);
        }

        private boolean check2(Integer[] arr, int mid) {
            for (int i = 0; i < arr.length; i++) {
                int pos = find(arr, mid + i) + 1 - i;
                if (pos <= 0)
                    return false;
            }
            return true;
        }

        private boolean check(Integer[] arr, int mid, int p) {
            if (find(arr, mid) == -1)
                return false;
            int temp = find(arr, mid);
            for (int i = 0; i < arr.length; i++) {
                if (i > 0 && temp < arr.length - 1 && arr[temp + 1] == mid + i) {
                    temp++;
                }
                int pos = temp + 1 - i;
                if (pos % p == 0)
                    return false;
            }
            return true;
        }

        private int find(Integer[] arr, int elem) {
            int low = 0, high = arr.length - 1;
            int toRet = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (arr[mid].intValue() <= elem) {
                    low = mid + 1;
                    toRet = mid;
                } else
                    high = mid - 1;
            }
            return toRet;
        }

        private int bs(Integer[] arr, int max) {
            int low = 1, high = max;
            int toRet = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (check2(arr, mid)) {
                    high = mid - 1;
                    toRet = high;
                } else
                    low = mid + 1;
            }
            return toRet;
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

    }
}