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();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            shuffle(arr);
            Arrays.sort(arr);
            int low = bs(arr, (int) 1e9), high = (int) 1e9;
            int start = low;
            int end = -1;
            if (start != -1) {
                while (low <= high) {
                    int mid = (low + high) / 2;
                    if (check(arr, mid, p)) {
                        low = mid + 1;
                        end = mid;
                    } else
                        high = mid - 1;
                }
            }
            if (end < start) {
                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 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) {
            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(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)) {
                    toRet = mid;
                    high = mid - 1;
                } 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.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];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            shuffle(arr);
            Arrays.sort(arr);
            int low = bs(arr, (int) 1e9), high = (int) 1e9;
            if (low == -1) {
                pw.println(0);
                pw.println();
                return;
            }
            int start = low;
            int end = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (check(arr, mid, p)) {
                    low = mid + 1;
                    end = mid;
                } else
                    high = mid - 1;
            }
            if (end < start) {
                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) {
            if (find(arr, mid) == -1)
                return false;
            int temp = find(arr, mid);
            for (int i = 0; i < arr.length; i++) {
                while (temp < arr.length && arr[temp] <= mid + i)
                    temp++;
                int pos = temp - 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)) {
                    toRet = mid;
                    high = mid - 1;
                } 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.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;
            }
            low = start;
            high = max;
            int end = start;
            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.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];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }
            shuffle(arr);
            Arrays.sort(arr);
            int low = bs(arr, (int) 1e9), high = (int) 1e9;
            if (low == -1) {
                pw.println(0);
                pw.println();
                return;
            }
            int start = low;
            int end = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (check(arr, mid, p)) {
                    low = mid + 1;
                    end = mid;
                } else
                    high = mid - 1;
            }
            if (end < start) {
                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) {
            int temp = 0;
            for (int i = 0; i < arr.length; i++) {
                while (temp < arr.length && arr[temp] <= mid + i)
                    temp++;
                int pos = temp - i;
                if (pos <= 0)
                    return false;
            }
            return true;
        }

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

        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)) {
                    toRet = mid;
                    high = mid - 1;
                } 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 = low;
            int end = -1;
            if (start != -1) {
                while (low <= high) {
                    int mid = (low + high) / 2;
                    if (check(arr, mid, p)) {
                        low = mid + 1;
                        end = mid;
                    } else
                        high = mid - 1;
                }
            }
            if (end < start) {
                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) {
            if (find(arr, mid) == -1)
                return false;
            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)) {
                    toRet = mid;
                    high = mid - 1;
                } 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.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;
            }
            low = 1;
            high = max;
            int end = start;
            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) {
            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(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());
        }

    }
}


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 = low;
            int end = -1;
            if (start != -1) {
                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) {
            if (find(arr, mid) == -1)
                return false;
            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)) {
                    toRet = mid;
                    high = mid - 1;
                } 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.*;
import java.util.*;

public class ProbE {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
    // main solver
    static class Task{
        int cnt[] = new int[2001];
        public void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int p = in.nextInt();
            int a[] = new int[n];
            int max = 0;
            for (int i = 0; i < n; i++){
                a[i] = in.nextInt();
                max = Math.max(max, a[i]);
            }
            ArrayList<Integer> l = new ArrayList<>();
            for (int tar = Math.max(1, max - n + 1); tar < max; tar++){
                int[] cnt = new int[n];
                int x = 0;
                for (int i = 0; i < n; i++){
                    cnt[Math.max(0, a[i] - tar)]++;
                }
                int i;
                for (i = 0; i < n; i++){
                    x += cnt[i];
                    if (x % p == 0 || x < 0){
                        break;
                    }
                    x--;
                }
                if (i == n){
                    l.add(tar);
                }
            }
            out.println(l.size());
            for (int num : l){
                out.print(num + " ");
            }
        }
    }
    // fast input reader class;
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        public long nextLong(){
            return Long.parseLong(nextToken());
        }
    }
}


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

public class ProbE {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
    // main solver
    static class Task{
        int cnt[] = new int[2001];
        public void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int p = in.nextInt();
            int a[] = new int[n];
            int max = 0;
            for (int i = 0; i < n; i++){
                a[i] = in.nextInt();
            }
            Arrays.sort(a);
            int start = 0, end = 1000000000;
            for (int i=  n - 1; i >= 0; i--){
                if (i + 1 >= p){
                    end = Math.min(end, a[i] - i + p - 2);
                }
                start = Math.max(start, a[i] - i);
            }
            out.println(Math.max(0, end - start + 1));
            for (int i = start; i <= end; i++){
                out.print(i + " ");
            }
        }
    }
    // fast input reader class;
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        public long nextLong(){
            return Long.parseLong(nextToken());
        }
    }
}


import java.util.*;
import java.io.*;
import java.util.zip.Adler32;

public class Main {
    static Integer[]a;
    static int p;
    static boolean check(int c){
        int id=0;
        boolean is=true;
        int n = a.length;
        for (int i =0;i<n;i++){
            while (id<n&&a[id]<=c+i){
                id++;
            }
            int num =id-i;
            if (num%p==0){
                is=false;
                break;
            }
        }
        return is;
    }
    static boolean check1(int c){
        int id=0;
        boolean is=true;
        int n = a.length;
        for (int i =0;i<n;i++){
            while (id<n&&a[id]<=c+i){
                id++;
            }
            int num =id-i;
            if (num<=0){
                is=false;
                break;
            }
        }
        return is;
    }

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
         p = sc.nextInt();
        a = new Integer[n];
        ArrayList<Integer>res= new ArrayList<>();
        for (int i =0;i<n;i++){
            a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        int ll=1;
        int hh=(int)1e9;
        int s1=-1;
        while (ll<=hh){
            int mm = (ll+hh)/2;
            if (check1(mm)){
                s1=mm;
                hh=mm-1;
            }
            else ll=mm+1;
        }
        if (s1==-1){
            pw.println(0);
            pw.flush();
            return;
        }
        ll=s1;
        hh=(int)1e9;
        int s2=-1;
        while (ll<=hh){
            int mm = (ll+hh)/2;
            if (check(mm)){
                s2=mm;
                ll=mm+1;
            }
            else hh=mm-1;
        }
        if (s2<s1){
            pw.println(0);
            pw.flush();
            return;
        }
        pw.println(s2-s1+1);
        for (int i =s1;i<=s2;i++)
            pw.print(i+" ");
        pw.println();
        pw.flush();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

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

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

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}


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

public class E {
    static final boolean RUN_TIMING = false;
    static char[] inputBuffer = new char[1 << 20];
    static PushbackReader in = new PushbackReader(new BufferedReader(new InputStreamReader(System.in)), 1 << 20);
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public void go() throws IOException {
        // in = new PushbackReader(new BufferedReader(new FileReader(new File("test.txt"))), 1 << 20);
        // out = new PrintWriter(new FileWriter(new File("output.txt")));
        int n = ipar();
        int p = ipar();
        int[] arr = iapar(n);
        ArrayList<Integer> list = new ArrayList<>();
        for (int x : arr) {
            list.add(x);
        }
        Collections.sort(list);
        for (int i = 0; i < n; i++) {
            arr[i] = list.get(i);
        }
        int l = 0;
        int r = arr[n-1];
        while (l < r) {
            int mid = (l+r)/2;
            int res = isValid(arr, p, mid);
            if (res < 0) {
                l = mid+1;
            } else {
                r = mid;
            }
        }
        int low = l;
        l = 0;
        r = arr[n-1];
        while (l < r) {
            int mid = (l+r+1)/2;
            int res = isValid(arr, p, mid);
            if (res <= 0) {
                l = mid;
            } else {
                r = mid-1;
            }
        }
        int high = l;
        out.println(high-low+1);
        for (int i = low; i <= high; i++) {
            out.print(i);
            out.print(" ");
        }
        out.println();
    }

    public int isValid(int[] arr, int p, int x) {
        int n = arr.length;
        int curr = x;
        int c = 0;
        int i = 0;
        while (i < n) {
            while (i < n && arr[i] <= curr) {
                i++;
                c++;
            }
            if (c == 0) {
                return -1;
            } else if (c >= p) {
                return 1;
            }
            c--;
            curr++;
        }
        return 0;
    }

    public int ipar() throws IOException {
        return Integer.parseInt(spar());
    }

    public int[] iapar(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = ipar();
        }
        return arr;
    }

    public long lpar() throws IOException {
        return Long.parseLong(spar());
    }

    public long[] lapar(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = lpar();
        }
        return arr;
    }

    public double dpar() throws IOException {
        return Double.parseDouble(spar());
    }

    public String spar() throws IOException {
        int len = 0;
        int c;
        do {
            c = in.read();
        } while (Character.isWhitespace(c) && c != -1);
        if (c == -1) {
            throw new NoSuchElementException("Reached EOF");
        }
        do {
            inputBuffer[len] = (char)c;
            len++;
            c = in.read();
        } while (!Character.isWhitespace(c) && c != -1);
        while (c != '\n' && Character.isWhitespace(c) && c != -1) {
            c = in.read();
        }
        if (c != -1 && c != '\n') {
            in.unread(c);
        }
        return new String(inputBuffer, 0, len);
    }

    public String linepar() throws IOException {
        int len = 0;
        int c;
        while ((c = in.read()) != '\n' && c != -1) {
            if (c == '\r') {
                continue;
            }
            inputBuffer[len] = (char)c;
            len++;
        }
        return new String(inputBuffer, 0, len);
    }

    public boolean haspar() throws IOException {
        String line = linepar();
        if (line.isEmpty()) {
            return false;
        }
        in.unread('\n');
        in.unread(line.toCharArray());
        return true;
    }

    public static void main(String[] args) throws IOException {
        long time = 0;
        time -= System.nanoTime();
        new E().go();
        time += System.nanoTime();
        if (RUN_TIMING) {
            System.out.printf("%.3f ms%n", time / 1000000.0);
        }
        out.flush();
        in.close();
    }
}


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

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

public class cf1371e2 {

    public static void main(String[] args) throws IOException {
        int n = rni(), p = ni(), a[] = ria(n), st = 0, max = 0;
        rsort(a);
        for(int i = 0; i < n; ++i) {
            st = max(st, a[i] - i);
            max = max(max, a[i]);
        }
        int ind = 0, j = max - st + 1;
        for(int k = 0; k <= max - st; ++k) {
            while(ind < n && a[ind] <= st + k) {
                ++ind;
            }
            if(ind >= p) {
                j = min(j, k - (ind - p));
            }
        }
        List<Integer> ans = new ArrayList<>();
        for(int i = 0; i < j; ++i) {
            ans.add(st + i);
        }
        prln(ans.size());
        prln(ans);
        close();
    }

    static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));
    static StringTokenizer input;
    static Random rand = new Random();

    // references
    // IBIG = 1e9 + 7
    // IMAX ~= 2e10
    // LMAX ~= 9e18

    // constants
    static final int IBIG = 1000000007;
    static final int IMAX = 2147483647;
    static final int IMIN = -2147483648;
    static final long LMAX = 9223372036854775807L;
    static final long LMIN = -9223372036854775808L;
    // math util
    static int minof(int a, int b, int c) {return min(a, min(b, c));}
    static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}
    static long minof(long a, long b, long c) {return min(a, min(b, c));}
    static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}
    static int maxof(int a, int b, int c) {return max(a, max(b, c));}
    static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}
    static long maxof(long a, long b, long c) {return max(a, max(b, c));}
    static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}
    static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
    static int floori(double d) {return (int)d;}
    static int ceili(double d) {return (int)ceil(d);}
    static long floorl(double d) {return (long)d;}
    static long ceill(double d) {return (long)ceil(d);}
    static int randInt(int min, int max) {return rand.nextInt(max - min + 1) + min;}
    // array util
    static void reverse(int[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
    static void reverse(long[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
    static void reverse(double[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {double swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
    static void reverse(char[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
    static <T> void reverse(T[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {T swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
    static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static void shuffle(double[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); double swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static void shuffle(char[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); char swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static <T> void shuffle(T[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); T swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
    static void rsort(int[] a) {shuffle(a); sort(a);}
    static void rsort(long[] a) {shuffle(a); sort(a);}
    static void rsort(double[] a) {shuffle(a); sort(a);}
    static void rsort(char[] a) {shuffle(a); sort(a);}
    static <T> void rsort(T[] a) {shuffle(a); sort(a);}
    // graph util
    static List<List<Integer>> graph(int n) {List<List<Integer>> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}
    static void connect(List<List<Integer>> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}
    static void connectDirected(List<List<Integer>> g, int u, int v) {g.get(u).add(v);};
    // input
    static void r() throws IOException {input = new StringTokenizer(__in.readLine());}
    static int ri() throws IOException {return Integer.parseInt(__in.readLine());}
    static long rl() throws IOException {return Long.parseLong(__in.readLine());}
    static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}
    static int[] riam1(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()) - 1; return a;}
    static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}
    static char[] rcha() throws IOException {return __in.readLine().toCharArray();}
    static String rline() throws IOException {return __in.readLine();}
    static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}
    static int ni() {return Integer.parseInt(input.nextToken());}
    static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}
    static long nl() {return Long.parseLong(input.nextToken());}
    // output
    static void pr(int i) {__out.print(i);}
    static void prln(int i) {__out.println(i);}
    static void pr(long l) {__out.print(l);}
    static void prln(long l) {__out.println(l);}
    static void pr(double d) {__out.print(d);}
    static void prln(double d) {__out.println(d);}
    static void pr(char c) {__out.print(c);}
    static void prln(char c) {__out.println(c);}
    static void pr(char[] s) {__out.print(new String(s));}
    static void prln(char[] s) {__out.println(new String(s));}
    static void pr(String s) {__out.print(s);}
    static void prln(String s) {__out.println(s);}
    static void pr(Object o) {__out.print(o);}
    static void prln(Object o) {__out.println(o);}
    static void prln() {__out.println();}
    static void pryes() {__out.println("yes");}
    static void pry() {__out.println("Yes");}
    static void prY() {__out.println("YES");}
    static void prno() {__out.println("no");}
    static void prn() {__out.println("No");}
    static void prN() {__out.println("NO");}
    static void pryesno(boolean b) {__out.println(b ? "yes" : "no");};
    static void pryn(boolean b) {__out.println(b ? "Yes" : "No");}
    static void prYN(boolean b) {__out.println(b ? "YES" : "NO");}
    static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
    static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
    static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next()); else __out.println();}
    static void h() {__out.println("hlfd");}
    static void flush() {__out.flush();}
    static void close() {__out.close();}
}


import java.io.*;
import java.util.*;
import java.math.*;
public class E {
	public static void main(String[] args)throws IOException {
		FastIO sc = new FastIO(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int p = sc.nextInt();
		int arr[] = new int[n];
		for(int i=0; i<n; ++i) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int val = 0;
		for(int i=0; i<n; ++i) {
			val = Math.max(val, arr[i]-i);
		}
		int l = val;
		int r = 1000000000;
		while(l<r) {
			int mid = l+(r-l)/2;
			boolean ok = false;
			for(int i=n-1; i>=0; --i) {
				int firstpos = Math.max(arr[i]-mid, 0);
				int possible = n-firstpos-(n-1-i);
				if(possible%p==0) ok = true;
			}
			if(ok) {
				r = mid;
			}else {
				l = mid+1;
			}
		}
		if(l==val) {
			System.out.println(0);
		}else {
			System.out.println(l-val);
			for(int i=val; i<l; ++i) {
				System.out.print(i + " ");
			}
		}
		out.close();
	}
	static class FastIO {
		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;
		public FastIO(String fileName) throws IOException {
			dis = new FileInputStream(fileName);
		}
		public FastIO(InputStream is) throws IOException {
			dis = is;
		}
		int nextInt() throws IOException {
			int ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return (negative) ? -ret : ret;
		}
		long nextLong() throws IOException {
			long ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}
			return (negative) ? -ret : ret;
		}
		byte nextByte() throws IOException {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}
		String next() throws IOException {
			StringBuffer ret = new StringBuffer();

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b > ' ') {
				ret.appendCodePoint(b);
				b = nextByte();
			}

			return ret.toString();
		}
	}
}


import java.io.*;
import java.util.*;
//import javafx.util.*;
import java.math.*;
//import java.lang.*;
public class Main
{

   // static int n;
//  static HashSet<Integer> adj[];

   // static int dist[];
   // static int remove[];
//    static boolean isLeaf[];
  //   static Long dp[][];
   // static int arr[];
  //  static boolean ok;
    // static long arr[];
    // static long sum[];
  //  static boolean ok;
    static long mod=1000000007;
 //   static HashSet<Integer> adjacency[];
    static final long oo=(long)1e18;
    public static void main(String[] args) throws IOException {
    //    Scanner sc=new Scanner(System.in);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        br = new BufferedReader(new InputStreamReader(System.in));
      //  int test=nextInt();
      int test=1;

        outer: while(test--!=0){
            int n=nextInt();
            int p=nextInt();
            int arr[]=new int[n];
            for(int i=0;i<n;i++){
                arr[i]=nextInt();
            }

            Arrays.sort(arr);
            ArrayList<Integer> ans=new ArrayList<>();
            int min_x=Math.max(arr[n-1]-n+1,arr[0]);
            int max_x=arr[n-1];
            //int dp[]=new int[max_x+1];

           for(int x=min_x;x<=max_x;x++){
                boolean ok=true;
                int a[]=new int[n];
                for(int i=0;i<n;i++){
                    a[i]=x+i;
                }
                int find=n-1;
              //  int i=n-1;
               // int cnt=0;
                for(int i=n-1;i>=0;){
                    while(i>=0&&arr[find]<=a[i]){

                        i--;
                    }
                    // n-1-find
                    int cnt=find-i;
                    find--;
                    if(cnt%p==0){
                        ok=false;
                        break;
                    }
                }
                if(find+1>=p){
                    ok=false;

                }
                if(ok)
                    ans.add(x);
                else if(ans.size()>0){
                    break;
                }

            }
            pw.println(ans.size());
            for(int a:ans){
                pw.print(a+" ");
            }
            pw.println();

        }

        pw.close();
    }

    static class Pair implements Comparable<Pair>{
        double g,ai,bi,sa,sb;
        Pair(double g,double ai,double bi){
          //  this.index=index;
            this.g=g;
            this.ai=ai;
            this.bi=bi;
            sa=g/ai;
            sb=g/bi;
            //this.z=z;
        }
        public int compareTo(Pair p){
            double a=Math.abs(sa-sb);
            double b=Math.abs(p.sa-p.sb);
            if(a>b){
                return 1;
            }
            else if(a==b){
                return 0;

            }
            else{
                return -1;
            }
        }
    }
   static void update(long tree[],int idx,long val){
        //println(idx);
        while(idx<1000006){

            tree[idx]+=val;
            idx+=(idx)&(-idx);
        }
    }
    static long sum(long tree[],int idx){
        long sum=0;
        while(idx>0){

            sum+=tree[idx];
            idx-=(idx)&(-idx);
        }
        return sum;
    }
    public static BufferedReader br;
    public static StringTokenizer st;
    public static String next() {
        while (st == null || !st.hasMoreTokens()) {
       try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    public static Integer nextInt() {
        return Integer.parseInt(next());
    }
    public static Long nextLong() {
        return Long.parseLong(next());
    }

    public static Double nextDouble() {
        return Double.parseDouble(next());
    }
    // static class Pair{
    //     int x;int y;
    //     Pair(int x,int y,int z){
    //         this.x=x;
    //         this.y=y;
    //        // this.z=z;
    //      //   this.z=z;
    //       //  this.i=i;
    //     }
    // }
    // static class sorting implements Comparator<Pair>{
    //     public int compare(Pair a,Pair b){
    //         //return (a.y)-(b.y);
    //         if(a.y==b.y){
    //             return -1*(a.z-b.z);
    //         }
    //         return (a.y-b.y);
    //     }
   // }

    static long ncr(long n,long r){

        if(r==0)
            return 1l;
        long val=ncr(n-1,r-1);
        val=(n*val);
        val=(val/r);
        return val;
    }

    public static int[] na(int n)throws IOException{
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = nextInt();
        return a;
    }
    static class query implements Comparable<query>{
        int l,r,idx,block;
        static int len;
        query(int l,int r,int i){
            this.l=l;
            this.r=r;
            this.idx=i;
            this.block=l/len;
        }
        public int compareTo(query a){
            return block==a.block?r-a.r:block-a.block;
        }
    }

    // static class sorting implements Comparator<Pair>{
    //     public int compare(Pair a1,Pair a2){
    //         if(o1.a==o2.a)
    //             return (o1.b>o2.b)?1:-1;
    //         else if(o1.a>o2.a)
    //             return 1;
    //         else
    //             return -1;
    //     }
    // }
    static boolean isPrime(int n) {
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;
        if (n % 2 == 0 ||
            n % 3 == 0)
            return false;

        for (int i = 5;
                 i * i <= n; i = i + 6)
            if (n % i == 0 ||
                n % (i + 2) == 0)
                return false;

        return true;
    }
    static int gcd(int a, int b) {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
    // To compute x^y under modulo m
    static long power(long x, long y, long m){
        if (y == 0)
            return 1;
        long p = power(x, y / 2, m) % m;
        p = (p * p) % m;

        if (y % 2 == 0)
            return p;
        else
            return (x * p) % m;
    }
    static long fast_pow(long base,long n,long M){
        if(n==0)
           return 1;
        if(n==1)
        return base;
        long halfn=fast_pow(base,n/2,M);
        if(n%2==0)
            return ( halfn * halfn ) % M;
        else
            return ( ( ( halfn * halfn ) % M ) * base ) % M;
    }
       static long modInverse(long n,long M){
        return fast_pow(n,M-2,M);
    }
    // (1,1)

    //     (3,2)   (3,5)

}


import java.io.*;
import java.util.*;
//import javafx.util.*;
import java.math.*;
//import java.lang.*;
public class Main
{

   // static int n;
//  static HashSet<Integer> adj[];

   // static int dist[];
   // static int remove[];
//    static boolean isLeaf[];
  //   static Long dp[][];
   // static int arr[];
  //  static boolean ok;
    // static long arr[];
    // static long sum[];
  //  static boolean ok;
    static long mod=1000000007;
 //   static HashSet<Integer> adjacency[];
    static final long oo=(long)1e18;
    public static void main(String[] args) throws IOException {
    //    Scanner sc=new Scanner(System.in);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        br = new BufferedReader(new InputStreamReader(System.in));
      //  int test=nextInt();
      int test=1;

        outer: while(test--!=0){
            int n=nextInt();
            int p=nextInt();
            int arr[]=new int[n];
            for(int i=0;i<n;i++){
                arr[i]=nextInt();
            }

            Arrays.sort(arr);
            ArrayList<Integer> ans=new ArrayList<>();

            int min_x=Math.max(arr[n-1]-n+1,arr[0]);
            for(int i=0;i<n;i++){
                min_x=Math.max(min_x,arr[i]-i);
            }
            int max_x=arr[n-1];
            //int dp[]=new int[max_x+1];
            int l=min_x;int r=max_x;
            int idx=min_x-1;
           while(l<=r){
                int x=(l+r)/2;
                boolean ok=true;
                int a[]=new int[n];
                for(int i=0;i<n;i++){
                    a[i]=x+i;
                }
                int find=n-1;
              //  int i=n-1;
               // int cnt=0;

                for(int i=n-1;i>=0;){
                    while(i>=0&&arr[find]<=a[i]){

                        i--;
                    }
                    // n-1-find
                    int cnt=find-i;
                    find--;
                    if(cnt%p==0){
                        ok=false;
                        break;
                    }
                }
                if(find+1>=p){
                    ok=false;

                }
                if(ok){
                    idx=x;
                    l=x+1;
                }
                else{
                    r=x-1;
                }

            }

            pw.println(idx-min_x+1);
            for(int i=min_x;i<=idx;i++){
                pw.print(i+" ");
            }
            pw.println();

        }

        pw.close();
    }

    static class Pair implements Comparable<Pair>{
        double g,ai,bi,sa,sb;
        Pair(double g,double ai,double bi){
          //  this.index=index;
            this.g=g;
            this.ai=ai;
            this.bi=bi;
            sa=g/ai;
            sb=g/bi;
            //this.z=z;
        }
        public int compareTo(Pair p){
            double a=Math.abs(sa-sb);
            double b=Math.abs(p.sa-p.sb);
            if(a>b){
                return 1;
            }
            else if(a==b){
                return 0;

            }
            else{
                return -1;
            }
        }
    }
   static void update(long tree[],int idx,long val){
        //println(idx);
        while(idx<1000006){

            tree[idx]+=val;
            idx+=(idx)&(-idx);
        }
    }
    static long sum(long tree[],int idx){
        long sum=0;
        while(idx>0){

            sum+=tree[idx];
            idx-=(idx)&(-idx);
        }
        return sum;
    }
    public static BufferedReader br;
    public static StringTokenizer st;
    public static String next() {
        while (st == null || !st.hasMoreTokens()) {
       try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

    public static Integer nextInt() {
        return Integer.parseInt(next());
    }
    public static Long nextLong() {
        return Long.parseLong(next());
    }

    public static Double nextDouble() {
        return Double.parseDouble(next());
    }
    // static class Pair{
    //     int x;int y;
    //     Pair(int x,int y,int z){
    //         this.x=x;
    //         this.y=y;
    //        // this.z=z;
    //      //   this.z=z;
    //       //  this.i=i;
    //     }
    // }
    // static class sorting implements Comparator<Pair>{
    //     public int compare(Pair a,Pair b){
    //         //return (a.y)-(b.y);
    //         if(a.y==b.y){
    //             return -1*(a.z-b.z);
    //         }
    //         return (a.y-b.y);
    //     }
   // }

    static long ncr(long n,long r){

        if(r==0)
            return 1l;
        long val=ncr(n-1,r-1);
        val=(n*val);
        val=(val/r);
        return val;
    }

    public static int[] na(int n)throws IOException{
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = nextInt();
        return a;
    }
    static class query implements Comparable<query>{
        int l,r,idx,block;
        static int len;
        query(int l,int r,int i){
            this.l=l;
            this.r=r;
            this.idx=i;
            this.block=l/len;
        }
        public int compareTo(query a){
            return block==a.block?r-a.r:block-a.block;
        }
    }

    // static class sorting implements Comparator<Pair>{
    //     public int compare(Pair a1,Pair a2){
    //         if(o1.a==o2.a)
    //             return (o1.b>o2.b)?1:-1;
    //         else if(o1.a>o2.a)
    //             return 1;
    //         else
    //             return -1;
    //     }
    // }
    static boolean isPrime(int n) {
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;
        if (n % 2 == 0 ||
            n % 3 == 0)
            return false;

        for (int i = 5;
                 i * i <= n; i = i + 6)
            if (n % i == 0 ||
                n % (i + 2) == 0)
                return false;

        return true;
    }
    static int gcd(int a, int b) {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
    // To compute x^y under modulo m
    static long power(long x, long y, long m){
        if (y == 0)
            return 1;
        long p = power(x, y / 2, m) % m;
        p = (p * p) % m;

        if (y % 2 == 0)
            return p;
        else
            return (x * p) % m;
    }
    static long fast_pow(long base,long n,long M){
        if(n==0)
           return 1;
        if(n==1)
        return base;
        long halfn=fast_pow(base,n/2,M);
        if(n%2==0)
            return ( halfn * halfn ) % M;
        else
            return ( ( ( halfn * halfn ) % M ) * base ) % M;
    }
       static long modInverse(long n,long M){
        return fast_pow(n,M-2,M);
    }
    // (1,1)

    //     (3,2)   (3,5)

}


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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    StringTokenizer st = new StringTokenizer(in.readLine());
    int n = Integer.parseInt(st.nextToken());
    int p = Integer.parseInt(st.nextToken());
    int[] a = new int[n];

    st = new StringTokenizer(in.readLine());
    for (int i = 0; i < n; ++i) {
      a[i] = Integer.parseInt(st.nextToken());
    }

    int[] result = solve(n, p, a);
    System.out.println(Math.max(0, result[1] - result[0]));
    for (int i = result[0]; i < result[1]; ++i) {
      System.out.print(i + " ");
    }
    System.out.println();

    in.close();
  }

  private static int[] solve(int n, int p, int[] a) {
    Arrays.sort(a);
    return new int[] { getMin(n, p, a), getMax(n, p, a) };
  }

  private static int getMin(int n, int p, int[] a) {
    int result = a[0];

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

    return result;
  }

  private static int getMax(int n, int p, int[] a) {
    int max = Integer.MAX_VALUE;

    for (int i = 0; p + i - 1 < n; ++i) {
      int value = a[p + i - 1];
      int index = binarySearch(a, value + 1);

      if (index - 1 == p + i - 1) {
        max = Math.min(max, value - i);
      }
    }

    return max;
  }

  private static int binarySearch(int[] a, int value) {
    int start = 0, end = a.length;

    while (start < end) {
      int mid = (start + end) / 2;

      if (a[mid] >= value) {
        end = mid;
      } else {
        start = mid + 1;
      }
    }

    return start;
  }
}


//package codeforces;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class E1 {

	static class IO
    {
        BufferedReader br;
        StringTokenizer st;

        public IO()
        {
            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;
        }
    }
	public static void main(String[] args) {
		IO fs = new IO();
		int n = fs.nextInt(); long p = fs.nextLong();
		long[] a = new long[n];
		for(int i = 0; i<n; i++) {
			a[i] = fs.nextLong();
		}
		Arrays.sort(a);
		int i = 0; long maxt = a[n-1],mint = Integer.MAX_VALUE;
		while(i<n) {
			if(count(a,maxt,n)-i<p)i++;
			else maxt--;
		}
		long start = 0,end = a[n-1];
		while(start<=end) {
			long mid = start + (end - start)/2;
			boolean found = true;
			for(i = 0; i<n; i++) {
				if(a[i]>mid+i) {
					found = false;
					break;
				}
			}
			if(found) {
				mint = Math.min(mint, mid);
				end = mid-1;
			}
			else start = mid+1;
		}
		if(mint<=maxt) {
			System.out.println(maxt-start);
			for(i = (int)mint; i<maxt; i++)System.out.print(i+" ");
			System.out.println();
		}
		else System.out.println(0);
	}
	public static int count(long[] a,long val,int n) {
		int low = 0,high = n-1;
		while(low <= high) {
			int mid = low + (high - low) / 2;
			if(a[mid] >= val) high = mid-1;
			else low = mid+1;
		}
		return low;
	}
}


package codeforces;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class E1 {

	static class IO
    {
        BufferedReader br;
        StringTokenizer st;

        public IO()
        {
            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;
        }
    }
	public static void main(String[] args) {
		IO fs = new IO();
		int n = fs.nextInt(),p = fs.nextInt();
		int[] a = new int[n];
		for(int i = 0; i<n; i++) {
			a[i] = fs.nextInt();
		}
		Arrays.sort(a);
		ArrayList<Integer> ans = new ArrayList<Integer>();
		for(int i = a[0]; i <= a[n-1]; ++i) {
			boolean ok = true;
			int start = i;
			for(int j = 0; j<n; j++) {
				int z = count(a,start,n);
				if((z-j)%p == 0) {
					ok = false;
					break;
				}
				else {
					start+=1;
				}
			}
			if(ok) {
				ans.add(i);
			}
			if(!ok)break;
		}
		System.out.println((int)ans.size());
		for(int x:ans)System.out.print(x-1+" ");
		System.out.println();
	}
	public static int count(int[] a,int val,int n) {
		int low = 0,high = n-1;
		while(low <= high) {
			int mid = low + (high - low) / 2;
			if(a[mid] >= val) high = mid-1;
			else low = mid+1;
		}
		return low;
	}
}


//package codeforces;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class E1 {

	static class IO
    {
        BufferedReader br;
        StringTokenizer st;

        public IO()
        {
            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;
        }
    }
	public static void main(String[] args) {
		IO fs = new IO();
		int n = fs.nextInt(); long p = fs.nextLong();
		long[] a = new long[n];
		for(int i = 0; i<n; i++) {
			a[i] = fs.nextLong();
		}
		Arrays.sort(a);
		int i = 0; long maxt = a[n-1],mint = Integer.MAX_VALUE;
		while(i<n) {
			if(count(a,maxt,n)-i<p)i++;
			else maxt--;
		}
		long start = 0,end = a[n-1];
		while(start<=end) {
			long mid = start + (end - start)/2;
			boolean found = true;
			for(i = 0; i<n; i++) {
				if(a[i]>mid+i) {
					found = false;
					break;
				}
			}
			if(found) {
				mint = Math.min(mint, mid);
				end = mid-1;
			}
			else start = mid+1;
		}
		if(mint<=maxt) {
			System.out.println(maxt-start);
			for(i = (int)start; i<maxt; i++)System.out.print(i+" ");
			System.out.println();
		}
		else System.out.println(0);
	}
	public static int count(long[] a,long val,int n) {
		int low = 0,high = n-1;
		while(low <= high) {
			int mid = low + (high - low) / 2;
			if(a[mid] >= val) high = mid-1;
			else low = mid+1;
		}
		return low;
	}
}


//package codeforces;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class E1 {

	static class IO
    {
        BufferedReader br;
        StringTokenizer st;

        public IO()
        {
            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;
        }
    }
	public static void main(String[] args) {
		IO fs = new IO();
		int n = fs.nextInt(),p = fs.nextInt();
		int[] a = new int[n];
		for(int i = 0; i<n; i++) {
			a[i] = fs.nextInt();
		}
		Arrays.sort(a);
		ArrayList<Integer> ans = new ArrayList<Integer>();
		for(int i = a[0]; i <= a[n-1]; ++i) {
			boolean ok = true;
			int start = i;
			for(int j = 0; j<n; j++) {
				int z = count(a,start,n);
				if((z-j)%p == 0) {
					ok = false;
					break;
				}
				else {
					start+=1;
				}
			}
			if(ok) {
				ans.add(i);
			}
			if(!ok)break;
		}
		System.out.println((int)ans.size());
		for(int x:ans)System.out.print(x-1+" ");
		System.out.println();
	}
	public static int count(int[] a,int val,int n) {
		int low = 0,high = n-1;
		while(low <= high) {
			int mid = low + (high - low) / 2;
			if(a[mid] >= val) high = mid-1;
			else low = mid+1;
		}
		return low;
	}
}


//package codeforces;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class E1 {

	static class IO
    {
        BufferedReader br;
        StringTokenizer st;

        public IO()
        {
            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;
        }
    }
	public static void main(String[] args) {
		IO fs = new IO();
		int n = fs.nextInt(),p = fs.nextInt();
		int[] a = new int[n];
		for(int i = 0; i<n; i++) {
			a[i] = fs.nextInt();
		}
		Arrays.sort(a);
		ArrayList<Integer> ans = new ArrayList<Integer>();
		for(int i = a[0]; i <= a[n-1]; ++i) {
			boolean ok = true;
			int start = i;
			for(int j = 0; j<n; j++) {
				int z = count(a,start,n);
				if((z-j)%p == 0) {
					ok = false;
					break;
				}
				else {
					start+=1;
				}
			}
			if(ok) {
				ans.add(i);
			}
		}
		System.out.println((int)ans.size());
		for(int x:ans)System.out.print(x-1+" ");
		System.out.println();
	}
	public static int count(int[] a,int val,int n) {
		int low = 0,high = n-1;
		while(low <= high) {
			int mid = low + (high - low) / 2;
			if(a[mid] >= val) high = mid-1;
			else low = mid+1;
		}
		return low;
	}
}


//package codeforces;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class E1 {

	static class IO
    {
        BufferedReader br;
        StringTokenizer st;

        public IO()
        {
            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;
        }
    }
	public static void main(String[] args) {
		IO fs = new IO();
		int n = fs.nextInt(),p = fs.nextInt();
		int[] a = new int[n];
		for(int i = 0; i<n; i++) {
			a[i] = fs.nextInt();
		}
		Arrays.sort(a);
		ArrayList<Integer> ans = new ArrayList<Integer>();
		int i = 0,maxt = a[n-1];
		while(i<n) {
			if(count(a,maxt,n)-i<p)i++;
			else maxt--;
		}
		int start = 0,end = a[n-1];
		while(start<=end) {
			int mid = start + (end - start)/2;
			boolean found = true;
			for(i = 0; i<n; i++) {
				if(a[i]>mid+i) {
					found = false;
					break;
				}
			}
			if(found) {
				end = mid-1;
			}
			else start = mid+1;
		}
		if(start<=maxt) {
		System.out.println(maxt-start);
		for(i = start; i<maxt; i++)System.out.print(i+" ");
		System.out.println();
		}
		else System.out.println(0);
	}
	public static int count(int[] a,int val,int n) {
		int low = 0,high = n-1;
		while(low <= high) {
			int mid = low + (high - low) / 2;
			if(a[mid] >= val) high = mid-1;
			else low = mid+1;
		}
		return low;
	}
}


//package codeforces;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class E1 {

	static class IO
    {
        BufferedReader br;
        StringTokenizer st;

        public IO()
        {
            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;
        }
    }
	public static void main(String[] args) {
		IO fs = new IO();
		int n = fs.nextInt(); long p = fs.nextLong();
		long[] a = new long[n];
		for(int i = 0; i<n; i++) {
			a[i] = fs.nextLong();
		}
		Arrays.sort(a);
		long mincandies = Integer.MAX_VALUE,maxcandies = Integer.MIN_VALUE;
		long low = 0,high = (long)1e9+9;
		while(low<=high) {
			long mid = low + (high - low) / 2;
			boolean ok = true;
			for(int i = 0; i<n; i++) {
				if(a[i]>mid+i) {
					ok = false;
					break;
				}
			}
			if(ok) {
				mincandies = mid;
				high = mid-1;
			}
			else low = mid+1;
		}
		low = mincandies;high = (long)1e9+9;
		while(low<=high) {
			long mid = low + (high - low) / 2;
			long perm = 1;
			for(int i = 0; i<n; i++) {
				perm = (perm*(count(a,mid+i,n)-i)%p)%p;
				if(perm == 0)break;
			}
			if(perm == 0) {
				high = mid-1;
			}
			else {
				maxcandies = mid;
				low = mid+1;
			}
		}
		if(mincandies<=maxcandies) {
			System.out.println(maxcandies-mincandies+1);
			for(long i = mincandies; i<=maxcandies; i++)System.out.print(i+" ");
			System.out.println();
		}
		else System.out.println(0);
	}
	public static long count(long[] a,long val,int n) {
		int ans = -1;
		int low = 0,high = n-1;
		while(low <= high) {
			int mid = low + (high - low) / 2;
			if(a[mid] > val) {
				high = mid-1;ans = mid;
			}
			else low = mid+1;
		}
		return ans == -1?n:ans;
	}
}


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

	 public class Main	{
	   static class Pair implements Comparable<Pair>{
	   int a;
	   int b;
	   public Pair(){}
	   public Pair(int x,int y){a=x;b=y;}
	   public int compareTo(Pair p){
		 return Integer.compare(a, p.a);
	   }
	//	   long a,b;
	//	   public Pair(long x,long y){a=x;b=y;}
	//	   public int compareTo(Pair p){
	//			 return Long.compare(a, p.a);
	//	   }
	//
	//	@Override
	//	public int hashCode() {
	//		final int prime = 31;
	//		int result = 1;
	//		result = prime * result + a;
	//		result = prime * result + b;
	//	//	out.println("hashcode = "+result);
	//		return result;
	//	}
	//	@Override
	//	public boolean equals(Object obj) {
	//		Pair cur = (Pair)obj;
	//		if((a==cur.a && b==cur.b) || (a==cur.b && b==cur.a))return true;
	//		return false;
	//	}
	 }
	   static class ArrayUtils {
		public static Integer[] generateOrder(int size) {
			Integer[] order = new Integer[size];
			for (int i = 0; i < size; i++)
				order[i] = i;
			return order;
		}

		public static Integer[] order(int size, Comparator<Integer> comparator) {
			Integer[] order = generateOrder(size);
			Arrays.sort(order, comparator);
			return order;
		}

			}
	   static class cell implements Comparable<cell>{
		   int a,b;
		   long dis;
		   public cell(int x,int y,long z) {a=x;b=y;dis=z;}
		   public int compareTo(cell c) {
			   return Long.compare(dis,c.dis);
		   }
	   }
	static class TrieNode{
		TrieNode left;
		TrieNode right;
		int op;
		int data;
		public TrieNode() {}
	}
	  public static int gcd(int a,int b)
	  {
	    if(a<b)

	      return gcd(b,a);
	    if(b==0)
	      return a;
	    return gcd(b,a%b);

	  }
	  static int lcm(int a,int b) {
		  return  a*b / gcd(a,b);
	  }
	  //static long ans = 0;
	  static long mod = (long)(1e9+7); //998244353;//

	    public static void main(String[] args) throws Exception {
	       new Thread(null, null, "Anshum Gupta", 99999999) {
	            public void run() {
	                try {
	                    solve();
	                } catch(Exception e) {
	                    e.printStackTrace();
	                    System.exit(1);
	                }
	            }
	        }.start();
	    }

	static long pow(long x,long y){
	    if(y == 0)return 1;
	    if(y==1)return x;
	    long a = pow(x,y/2);
	    a = (a*a)%mod;
	    if(y%2==0){
	        return a;
	    }
	    return (a*x)%mod;
	}

	static long mxx;
	static int mxN = (int)(2e6+5);
	static long[]fact,inv_fact;
	static long my_inv(long a) {
		return pow(a,mod-2);
	}
	static long bin(int a,int b) {
		if(a < b || a<0 || b<0)return 0;
	    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
	}
		static ArrayList<ArrayList<Integer>>adj;
		static boolean[]vis;
	static void make_facts() {
	  fact=new long[mxN];
	  inv_fact = new long[mxN];
	  fact[0]=inv_fact[0]=1L;
	  for(int i=1;i<mxN;i++) {
		   fact[i] = (i*fact[i-1])%mod;
		   inv_fact[i] = my_inv(fact[i]);
	  }
	}
	static int find(int val) {
		int res = 0;
		int l = 0, r = n;
		while(l <= r) {
			int mid = (l + r)/2;
			if(a[mid] <= val) {
				res = mid;
				l = mid + 1;
			}
			else r = mid - 1;
		}
		return res;
	}
	static int f(int x) {
		int ans = 0;
		for(int i=1;i<=n;i++) { // how many values can I place here?
			int cnt = find(x+i-1);
//			ans *= (cnt - i + 1)
			if(cnt - i + 1 == 0)return -1;
			if((cnt-i+1) % p == 0) {
				ans = 1;
			}
		}
		return ans;
	}
	static int find_min() {
		int res = (int)1e9;
		int l = a[1], r = a[n];
		while(l <= r) {
			int mid = (l + r) >> 1;
			int val = f(mid);
			if(val == -1) {
				l = mid+1;
			}
			else if(val == 0) {
				res = Math.min(mid, res);
				r = mid - 1;
			}
			else {
				r = mid - 1;
			}

		}
		return res;
	}
	static int find_max() {
		int res = 0;
		int l = a[1], r = a[n];
		while(l <= r) {
			int mid = (l + r) >> 1;
			int val = f(mid);
			if(val == -1) {
				l = mid+1;
			}
			else if(val == 0) {
				res = Math.max(mid, res);
				l = mid + 1;
			}
			else {
				r = mid - 1;
			}

		}
		return res;
	}
	static int n;
	static Integer[]a;
	static int p;
	 public static void solve() throws Exception {
	   // solve the problem here
	   MyScanner s = new MyScanner();
	        out = new PrintWriter(new BufferedOutputStream(System.out), true);
	        int tc = 1;//s.nextInt();
	        mxx = (long)(1e18+5);
	//	        make_facts();
	//	        int mod = (int)1e9+7;
	        while(tc-->0){
	        	n = s.nextInt();
	        	p = s.nextInt();
	        	a = new Integer[n+1];
	        	a[0] = 0;
	        	for(int i=1;i<=n;i++) {
	        		a[i] = s.nextInt();
	        	}
	        	Arrays.sort(a);
	        	ArrayList<Integer> ans = new ArrayList<Integer>();
	        	int l = find_min();
	        	int r = find_max();
//	        	out.println(l + " " + r);
	        	for(int i=l;i<=r;i++) { // potential value of x
	        		if(true) {
	        			ans.add(i);
	        		}
	        	}
	        	out.println(ans.size());
	        	for(Integer x : ans) {
	        		out.print(x +  " ");
	        	}
	        }

	        out.flush();
	}

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

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

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

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

	        int nextInt() { return Integer.parseInt(next()); }
	        long nextLong() { return Long.parseLong(next()); }
	        double nextDouble() { return Double.parseDouble(next()); }

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


import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class template {
	public static void main(String[] args) throws Exception {
		new template().run();
	}
	public void run() throws Exception {
		FastScanner f = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		///
		int n = f.nextInt(), p = f.nextInt();
		Integer[] arr = new Integer[n];
		for(int i = 0; i < n; i++) arr[i] = f.nextInt();
		Arrays.sort(arr);
		int l = 0, max = 1000000001;
		while(l < max) {
			int m = (l+max)/2;
			boolean ok = true;
			int i = 0;
			int c = 0;
			int cur = m;
			while(i < n) {
				if(arr[i] <= cur) {
					i++;
					c++;
				} else {
					c -= arr[i]-cur;
					cur = arr[i];
					c++;
					i++;
				}
				if(c <= 0) {
					ok = true;
					break;
				}
				ok &= c < p;
			}
			if(!ok) max = m;
			else l = m+1;
		}
		l = 0; int min = 1000000001;
		while(l < min) {
			int m = (l+min)/2;
			boolean ok = true;
			int i = 0;
			int c = 0;
			int cur = m;
			while(i < n) {
				if(arr[i] <= cur) {
					i++;
					c++;
				} else {
					c -= arr[i]-cur;
					cur = arr[i];
					c++;
					i++;
				}
				if(c <= 0) {
					ok = false;
					break;
				}
			}
			if(ok) min = m;
			else l = m+1;
		}
		out.println(Math.max(max-min, 0));
		for(int i = min; i < max; i++)
			out.print(i + " ");
		out.println();
///
		out.flush();
	}
///
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch(IOException e) {
				throw new RuntimeException(e);
			}
		}
	}
}