import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class C {

	public static void main(String[] args) throws Exception {
		FastScanner sc = new FastScanner(System.in);
		FastPrinter out = new FastPrinter(System.out);
		C runner = new C();
		int Q = sc.nextInt();
		for (int i = 0; i < Q; i++) {
			runner.run(sc, out);
		}
		out.close();
	}

	public void run(FastScanner sc, FastPrinter out) throws Exception {
		int h = sc.nextInt();
		int n = sc.nextInt();
		int ans = 0;
		int[] arr = new int[n + 1];
		for (int i = 0; i < n; i++)
			arr[i] = sc.nextInt();
		for (int i = 1; i < n - 1; i++) {
			int fall = arr[i] - arr[i + 1] + 1;
			if (fall > 2) {
				ans++;
			}

		}
		out.println(ans);
	}

	public void shuffle(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			int r = (int) (Math.random() * arr.length);
			if (i != r) {
				arr[i] ^= arr[r];
				arr[r] ^= arr[i];
				arr[i] ^= arr[r];
			}
		}
	}

	static class FastScanner {
		final private int BUFFER_SIZE = 1 << 10;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

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

		public FastScanner(InputStream stream) {
			din = new DataInputStream(stream);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public FastScanner(String fileName) throws IOException {
			Path p = Paths.get(fileName);
			buffer = Files.readAllBytes(p);
			bytesRead = buffer.length;
		}

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

		String nextLine() throws IOException {
			int c = read();
			while (c != -1 && isEndline(c))
				c = read();
			if (c == -1) {
				return null;
			}
			StringBuilder res = new StringBuilder();
			do {
				if (c >= 0) {
					res.appendCodePoint(c);
				}
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

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

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

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

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

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

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

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

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

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

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

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

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

		private int readOutSpaces() throws IOException {
			while (true) {
				if (bufferPointer == bytesRead) fillBuffer();
				int c = buffer[bufferPointer++];
				if (!isSpaceChar(c)) {
					return c;
				}
			}
		}

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

		public int[][] readGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {
			int[][] adj = new int[N][];
			int[] numNodes = new int[N];
			int[][] input = new int[M][2];
			for (int i = 0; i < M; i++) {
				int a = nextInt();
				int b = nextInt();
				if (zeroIndexed) {
					a--;
					b--;
				}
				input[i][0] = a;
				input[i][1] = b;
				numNodes[a]++;
				if (bidirectional) numNodes[b]++;
			}
			for (int i = 0; i < N; i++) {
				adj[i] = new int[numNodes[i]];
				numNodes[i] = 0;
			}
			for (int i = 0; i < M; i++) {
				int a = input[i][0];
				int b = input[i][1];
				adj[a][numNodes[a]++] = b;
				if (bidirectional) adj[b][numNodes[b]++] = a;
			}
			return adj;
		}

		public int[][][] readWeightedGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {
			int[][][] adj = new int[N][][];
			int[] numNodes = new int[N];
			int[][] input = new int[M][3];
			for (int i = 0; i < M; i++) {
				int a = nextInt();
				int b = nextInt();
				if (zeroIndexed) {
					a--;
					b--;
				}
				int d = nextInt();
				input[i][0] = a;
				input[i][1] = b;
				input[i][2] = d;
				numNodes[a]++;
				if (bidirectional) numNodes[b]++;
			}
			for (int i = 0; i < N; i++) {
				adj[i] = new int[numNodes[i]][2];
				numNodes[i] = 0;
			}
			for (int i = 0; i < M; i++) {
				int a = input[i][0];
				int b = input[i][1];
				int d = input[i][2];
				adj[a][numNodes[a]][0] = b;
				adj[a][numNodes[a]][1] = d;
				numNodes[a]++;
				if (bidirectional) {
					adj[b][numNodes[b]][0] = a;
					adj[b][numNodes[b]][1] = d;
					numNodes[b]++;
				}
			}
			return adj;
		}
	}

	static class FastPrinter {
		static final char ENDL = '\n';
		StringBuilder buf;
		PrintWriter pw;

		public FastPrinter(OutputStream stream) {
			buf = new StringBuilder();
			pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
		}

		public FastPrinter(String fileName) throws Exception {
			buf = new StringBuilder();
			pw = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
		}

		public FastPrinter(StringBuilder buf) {
			this.buf = buf;
		}

		public void print(int a) {
			buf.append(a);
		}

		public void print(long a) {
			buf.append(a);
		}

		public void print(char a) {
			buf.append(a);
		}

		public void print(char[] a) {
			buf.append(a);
		}

		public void print(double a) {
			buf.append(a);
		}

		public void print(String a) {
			buf.append(a);
		}

		public void print(Object a) {
			buf.append(a.toString());
		}

		public void println() {
			buf.append(ENDL);
		}

		public void println(int a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(long a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(char a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(char[] a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(double a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(String a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(Object a) {
			buf.append(a.toString());
			buf.append(ENDL);
		}

		public void printf(String format, Object... args) {
			buf.append(String.format(format, args));
		}

		public void close() {
			pw.print(buf);
			pw.close();
		}

		public void flush() {
			pw.print(buf);
			pw.flush();
			buf.setLength(0);
		}

	}

}


import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class C {

	public static void main(String[] args) throws Exception {
		FastScanner sc = new FastScanner(System.in);
		FastPrinter out = new FastPrinter(System.out);
		C runner = new C();
		int Q = sc.nextInt();
		for (int i = 0; i < Q; i++) {
			runner.run(sc, out);
		}
		out.close();
	}

	public void run(FastScanner sc, FastPrinter out) throws Exception {
		int h = sc.nextInt();
		int n = sc.nextInt();
		int ans = 0;
		int[] arr = new int[n + 1];
		for (int i = 0; i < n; i++)
			arr[i] = sc.nextInt();
		for (int i = 1; i < n; i++) {
			int fall = arr[i] - arr[i + 1] + 1;
			if (fall > 2) {
				ans++;
			} else {
				i++;
			}

		}
		out.println(ans);
	}

	public void shuffle(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			int r = (int) (Math.random() * arr.length);
			if (i != r) {
				arr[i] ^= arr[r];
				arr[r] ^= arr[i];
				arr[i] ^= arr[r];
			}
		}
	}

	static class FastScanner {
		final private int BUFFER_SIZE = 1 << 10;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

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

		public FastScanner(InputStream stream) {
			din = new DataInputStream(stream);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public FastScanner(String fileName) throws IOException {
			Path p = Paths.get(fileName);
			buffer = Files.readAllBytes(p);
			bytesRead = buffer.length;
		}

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

		String nextLine() throws IOException {
			int c = read();
			while (c != -1 && isEndline(c))
				c = read();
			if (c == -1) {
				return null;
			}
			StringBuilder res = new StringBuilder();
			do {
				if (c >= 0) {
					res.appendCodePoint(c);
				}
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

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

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

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

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

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

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

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

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

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

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

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

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

		private int readOutSpaces() throws IOException {
			while (true) {
				if (bufferPointer == bytesRead) fillBuffer();
				int c = buffer[bufferPointer++];
				if (!isSpaceChar(c)) {
					return c;
				}
			}
		}

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

		public int[][] readGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {
			int[][] adj = new int[N][];
			int[] numNodes = new int[N];
			int[][] input = new int[M][2];
			for (int i = 0; i < M; i++) {
				int a = nextInt();
				int b = nextInt();
				if (zeroIndexed) {
					a--;
					b--;
				}
				input[i][0] = a;
				input[i][1] = b;
				numNodes[a]++;
				if (bidirectional) numNodes[b]++;
			}
			for (int i = 0; i < N; i++) {
				adj[i] = new int[numNodes[i]];
				numNodes[i] = 0;
			}
			for (int i = 0; i < M; i++) {
				int a = input[i][0];
				int b = input[i][1];
				adj[a][numNodes[a]++] = b;
				if (bidirectional) adj[b][numNodes[b]++] = a;
			}
			return adj;
		}

		public int[][][] readWeightedGraph(int N, int M, boolean zeroIndexed, boolean bidirectional) throws Exception {
			int[][][] adj = new int[N][][];
			int[] numNodes = new int[N];
			int[][] input = new int[M][3];
			for (int i = 0; i < M; i++) {
				int a = nextInt();
				int b = nextInt();
				if (zeroIndexed) {
					a--;
					b--;
				}
				int d = nextInt();
				input[i][0] = a;
				input[i][1] = b;
				input[i][2] = d;
				numNodes[a]++;
				if (bidirectional) numNodes[b]++;
			}
			for (int i = 0; i < N; i++) {
				adj[i] = new int[numNodes[i]][2];
				numNodes[i] = 0;
			}
			for (int i = 0; i < M; i++) {
				int a = input[i][0];
				int b = input[i][1];
				int d = input[i][2];
				adj[a][numNodes[a]][0] = b;
				adj[a][numNodes[a]][1] = d;
				numNodes[a]++;
				if (bidirectional) {
					adj[b][numNodes[b]][0] = a;
					adj[b][numNodes[b]][1] = d;
					numNodes[b]++;
				}
			}
			return adj;
		}
	}

	static class FastPrinter {
		static final char ENDL = '\n';
		StringBuilder buf;
		PrintWriter pw;

		public FastPrinter(OutputStream stream) {
			buf = new StringBuilder();
			pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
		}

		public FastPrinter(String fileName) throws Exception {
			buf = new StringBuilder();
			pw = new PrintWriter(new BufferedWriter(new FileWriter(fileName)));
		}

		public FastPrinter(StringBuilder buf) {
			this.buf = buf;
		}

		public void print(int a) {
			buf.append(a);
		}

		public void print(long a) {
			buf.append(a);
		}

		public void print(char a) {
			buf.append(a);
		}

		public void print(char[] a) {
			buf.append(a);
		}

		public void print(double a) {
			buf.append(a);
		}

		public void print(String a) {
			buf.append(a);
		}

		public void print(Object a) {
			buf.append(a.toString());
		}

		public void println() {
			buf.append(ENDL);
		}

		public void println(int a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(long a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(char a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(char[] a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(double a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(String a) {
			buf.append(a);
			buf.append(ENDL);
		}

		public void println(Object a) {
			buf.append(a.toString());
			buf.append(ENDL);
		}

		public void printf(String format, Object... args) {
			buf.append(String.format(format, args));
		}

		public void close() {
			pw.print(buf);
			pw.close();
		}

		public void flush() {
			pw.print(buf);
			pw.flush();
			buf.setLength(0);
		}

	}

}


import java.util.*;
import java.io.*;
public class Main{
    static PrintWriter out;
    static InputReader in;
    public static void main(String args[]){
        out = new PrintWriter(System.out);
        in = new InputReader();
        new Main();
        out.flush(); out.close();
    }
    Main(){
        solve();
    }
    void solve(){
        int q = in.nextInt();
        while(q-- > 0){
            int h = in.nextInt(), n = in.nextInt();
            int a[] = new int[n];
            for(int i = 0; i < n; i++)a[i] = in.nextInt();
            ArrayList<Integer> al = new ArrayList<>();
            int cnt, j;
            for(int i = 0; i < n; i = j){
                cnt = 1;
                for(j = i + 1; j < n; j++){
                    if(a[j] == a[j - 1] - 1)cnt++;
                    else{
                        break;
                    }
                }
                al.add(cnt);
            }
            int ans = 0;
            int sz = al.size();
            int add = 0;
            for(int i = 0; i < sz; i++){
                add = 1 - (al.get(i) + add) % 2;
                if(i < sz - 1){
                    ans += add;
                }else{
                    if(a[n - 1] >= 2)ans += add;
                }
                add = 1;
            }
            out.println(ans);
        }
    }
    public static class InputReader{
        BufferedReader br;
        StringTokenizer st;
        InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
        public String next(){
            while(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch(IOException e){}
            }
            return st.nextToken();
        }
    }
}


import java.util.*;
import java.io.*;
public class Main{
    static PrintWriter out;
    static InputReader in;
    public static void main(String args[]){
        out = new PrintWriter(System.out);
        in = new InputReader();
        new Main();
        out.flush(); out.close();
    }
    Main(){
        solve();
    }
    void solve(){
        int q = in.nextInt();
        while(q-- > 0){
            int h = in.nextInt(), n = in.nextInt();
            int a[] = new int[n];
            for(int i = 0; i < n; i++)a[i] = in.nextInt();
            ArrayList<Integer> al = new ArrayList<>();
            int cnt, j;
            for(int i = 0; i < n; i = j){
                cnt = 1;
                for(j = i + 1; j < n; j++){
                    if(a[j] == a[j - 1] - 1)cnt++;
                    else{
                        break;
                    }
                }
                al.add(cnt);
            }
            int ans = 0;
            int sz = al.size();
            int add = 0;
            for(int i = 0; i < sz; i++){
                add = 1 - (al.get(i) + add) % 2;
                if(i < sz - 1){
                    ans += add;
                }else{
                    if(a[n - 1] >= 2)ans += add;
                }
            }
            out.println(ans);
        }
    }
    public static class InputReader{
        BufferedReader br;
        StringTokenizer st;
        InputReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
        public String next(){
            while(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch(IOException e){}
            }
            return st.nextToken();
        }
    }
}


import java.util.*;
public class Solution1238C{
    static int[] dp;
    public static int fxn(int[] states, int h){
        dp=new int[h+1];
        Arrays.fill(dp,-1);
        dp[0]=0;
        dp[h]= util(states, h);
        // System.out.println(Arrays.toString(dp));
        return dp[h];
    }
    public static int util(int[] states, int h){
        // System.out.println("h="+h +" states="+Arrays.toString(states)+" dp="+Arrays.toString(dp));
        if(h==0||h==2||h==1){
            return 0;
        }

        if(dp[h]!=-1){
            return dp[h];
        }
        if(states[h-1]==0){
            // states[h]=0;
            states[h-1]=1;
            dp[h]=util(states,h-1);
        }else{

            if(states[h-2]==0){
                dp[h]=1+util(states,h-1);
            }else{
                dp[h]=util(states,h-2);
            }
        }
        return dp[h];
    }
    public static void main (String[] args){
        Scanner in =new Scanner(System.in);
        int q=in.nextInt();
        while(q-->0){
            int h=in.nextInt();
            int[] states=new int[h+1];
            int n=in.nextInt();
            while(n-->0){
                states[in.nextInt()]++;
            }
            System.out.println(fxn(states,h));
        }
    }
}


import java.util.*;
public class Solution1238C{
    static int[] dp;
    public static int fxn(int[] states, int h){
        dp=new int[h+1];
        Arrays.fill(dp,-1);
        dp[0]=0;
        dp[h]= util(states, h);
        // System.out.println(Arrays.toString(dp));
        return dp[h];
    }
    public static int util(int[] states, int h){
        // System.out.println("h="+h +" states="+Arrays.toString(states)+" dp="+Arrays.toString(dp));
        if(h==0||h==2){
            return 0;
        }
        if(h==1){
            return 1;
        }
        if(dp[h]!=-1){
            return dp[h];
        }
        if(states[h-1]==0){
            // states[h]=0;
            states[h-1]=1;
            dp[h]=util(states,h-1);
        }else{

            if(states[h-2]==0){
                dp[h]=1+util(states,h-1);
            }else{
                dp[h]=util(states,h-2);
            }
        }
        return dp[h];
    }
    public static void main (String[] args){
        Scanner in =new Scanner(System.in);
        int q=in.nextInt();
        while(q-->0){
            int h=in.nextInt();
            int[] states=new int[h+1];
            int n=in.nextInt();
            while(n-->0){
                states[in.nextInt()]++;
            }
            System.out.println(fxn(states,h));
        }
    }
}


import java.util.*;
public class Solution1238C{

    public static void main (String[] args){
        Scanner sc=new Scanner(System.in);
		int T=sc.nextInt();
		int str[]=new int[10000005];
		while(T--!=0)
		{
			int n=sc.nextInt(),m=sc.nextInt(),ans=0;
			for(int i=1;i<=m;i++)
				str[i]=sc.nextInt();
			str[m+1]=0;
			for(int i=2;i<=m;i++)
			{
				if(str[i]-1==str[i+1])
					i++;
				else
					ans++;
			}
			System.out.println(ans);
	}
    }
}


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

import static java.lang.Math.*;

public class Solution implements Runnable
{
	static class InputReader
	{
		private InputStream stream;private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public InputReader(InputStream stream){this.stream = stream;}
		public int read(){if (numChars==-1) throw new InputMismatchException();if (curChar >= numChars){curChar = 0;try{numChars = stream.read(buf);}catch (IOException e){throw new InputMismatchException();	}if(numChars <= 0)return -1;}return buf[curChar++];}
     	public String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
		public int nextInt(){int c = read();	while(isSpaceChar(c))c = read();	int sgn = 1; if (c == '-'){sgn = -1;c = read();	}int res = 0;do{if(c<'0'||c>'9') throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
        public long nextLong(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}long res = 0;do{if (c < '0' || c > '9')throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
		public double nextDouble(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}double res = 0;while (!isSpaceChar(c) && c != '.'){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')
		throw new InputMismatchException();res *= 10;res += c - '0';c = read();}if (c == '.'){c = read();double m = 1;while (!isSpaceChar(c)){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')throw new InputMismatchException();m /= 10;res += (c - '0') * m;c = read();}}return res * sgn;}
        public String readString(){int c = read();while (isSpaceChar(c))c = read();StringBuilder res = new StringBuilder();do{res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
		public boolean isSpaceChar(int c){if (filter != null)return filter.isSpaceChar(c);return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;}
		public String next(){return readString();}
        public interface SpaceCharFilter{public boolean isSpaceChar(int ch);}
	}

	public static void main(String args[]) throws Exception{new Thread(null, new Solution(),"Main",1<<27).start();}

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

	public static int findGCD(int arr[], int n) { 	int result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result);return result; }

	static long power(long x, long y) { long temp; if( y == 0) return 1; temp = power(x, y/2)%1000000007;  if (y%2 == 0)  return (temp*temp)%1000000007;
        else{ if(y > 0) return (((x*temp)%1000000007)*temp)%1000000007; else return (((temp*temp)%1000000007)/x)%1000000007; } }

	static void sortbycolomn(long arr[][], int col)
    {
        Arrays.sort(arr, new Comparator<long[]>() {
        @Override
        public int compare(final long[] entry1,final long[] entry2) {
            if (entry1[col] > entry2[col])return 1;
            else return -1;
        }
        });
    }

	public void run()
    {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int t=in.nextInt();
        while(t--!=0){
            int h=in.nextInt();
            int n=in.nextInt();
            int[] arr=new int[n];
            for(int i=0;i<n;i++) arr[i]=in.nextInt();

            if(h==2 || h==1){
                w.println("0");
                continue;
            }
            else if(h==3 && n==3){
                w.println("0");
                continue;
            }
            else if(h==3 && n==2){
                if(arr[1]==1)
                    w.println("0");
                else
                    w.println("1");

                continue;
            }
            else if(n==1){
                w.println("0");
                continue;
            }

            int count=0;
            int pre=arr[0];
            int flag=0;

            for(int i=1;i<n-1;){
                if(pre-arr[i]==1){
                    if(arr[i+1]==pre-2){
                        pre=arr[i+1];
                        flag=2;
                        i+=2;
                    }
                    else{
                        pre=pre-2;
                        i++;
                        flag=0;
                        count++;
                    }
                }
                else{
                    pre=arr[i]+1;
                }
            }

            if(pre-arr[n-1]!=2 && arr[n-1]!=1)
                count++;

            w.println(count);

        }

        w.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class Solution implements Runnable
{
	static class InputReader
	{
		private InputStream stream;private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public InputReader(InputStream stream){this.stream = stream;}
		public int read(){if (numChars==-1) throw new InputMismatchException();if (curChar >= numChars){curChar = 0;try{numChars = stream.read(buf);}catch (IOException e){throw new InputMismatchException();	}if(numChars <= 0)return -1;}return buf[curChar++];}
     	public String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
		public int nextInt(){int c = read();	while(isSpaceChar(c))c = read();	int sgn = 1; if (c == '-'){sgn = -1;c = read();	}int res = 0;do{if(c<'0'||c>'9') throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
        public long nextLong(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}long res = 0;do{if (c < '0' || c > '9')throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
		public double nextDouble(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}double res = 0;while (!isSpaceChar(c) && c != '.'){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')
		throw new InputMismatchException();res *= 10;res += c - '0';c = read();}if (c == '.'){c = read();double m = 1;while (!isSpaceChar(c)){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')throw new InputMismatchException();m /= 10;res += (c - '0') * m;c = read();}}return res * sgn;}
        public String readString(){int c = read();while (isSpaceChar(c))c = read();StringBuilder res = new StringBuilder();do{res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
		public boolean isSpaceChar(int c){if (filter != null)return filter.isSpaceChar(c);return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;}
		public String next(){return readString();}
        public interface SpaceCharFilter{public boolean isSpaceChar(int ch);}
	}

	public static void main(String args[]) throws Exception{new Thread(null, new Solution(),"Main",1<<27).start();}

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

	public static int findGCD(int arr[], int n) { 	int result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result);return result; }

	static long power(long x, long y) { long temp; if( y == 0) return 1; temp = power(x, y/2)%1000000007;  if (y%2 == 0)  return (temp*temp)%1000000007;
        else{ if(y > 0) return (((x*temp)%1000000007)*temp)%1000000007; else return (((temp*temp)%1000000007)/x)%1000000007; } }

	static void sortbycolomn(long arr[][], int col)
    {
        Arrays.sort(arr, new Comparator<long[]>() {
        @Override
        public int compare(final long[] entry1,final long[] entry2) {
            if (entry1[col] > entry2[col])return 1;
            else return -1;
        }
        });
    }

	public void run()
    {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int t=in.nextInt();
        while(t--!=0){
            int h=in.nextInt();
            int n=in.nextInt();
            int[] arr=new int[n];
            for(int i=0;i<n;i++) arr[i]=in.nextInt();

            if(h==2 || h==1){
                w.println("0");
                continue;
            }
            else if(h==3 && n==3){
                w.println("0");
                continue;
            }
            else if(h==3 && n==2){
                if(arr[1]==1)
                    w.println("0");
                else
                    w.println("1");

                continue;
            }
            else if(n==1){
                w.println("0");
                continue;
            }

            int count=0;
            int pre=arr[0];
            int flag=0;

            for(int i=1;i<n-1;){
                if(pre-arr[i]==1){
                    if(arr[i+1]==pre-2){
                        pre=arr[i+1];
                        flag=2;
                        i+=2;
                    }
                    else{
                        pre=pre-2;
                        i++;
                        flag=0;
                        count++;
                    }
                }
                else{
                    pre=arr[i]+1;
                }
            }

            if(flag==0 && pre-arr[n-1]!=2 && arr[n-1]!=1)
                count++;

            w.println(count);

        }

        w.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class Solution implements Runnable
{
	static class InputReader
	{
		private InputStream stream;private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public InputReader(InputStream stream){this.stream = stream;}
		public int read(){if (numChars==-1) throw new InputMismatchException();if (curChar >= numChars){curChar = 0;try{numChars = stream.read(buf);}catch (IOException e){throw new InputMismatchException();	}if(numChars <= 0)return -1;}return buf[curChar++];}
     	public String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
		public int nextInt(){int c = read();	while(isSpaceChar(c))c = read();	int sgn = 1; if (c == '-'){sgn = -1;c = read();	}int res = 0;do{if(c<'0'||c>'9') throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
        public long nextLong(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}long res = 0;do{if (c < '0' || c > '9')throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
		public double nextDouble(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}double res = 0;while (!isSpaceChar(c) && c != '.'){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')
		throw new InputMismatchException();res *= 10;res += c - '0';c = read();}if (c == '.'){c = read();double m = 1;while (!isSpaceChar(c)){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')throw new InputMismatchException();m /= 10;res += (c - '0') * m;c = read();}}return res * sgn;}
        public String readString(){int c = read();while (isSpaceChar(c))c = read();StringBuilder res = new StringBuilder();do{res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
		public boolean isSpaceChar(int c){if (filter != null)return filter.isSpaceChar(c);return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;}
		public String next(){return readString();}
        public interface SpaceCharFilter{public boolean isSpaceChar(int ch);}
	}

	public static void main(String args[]) throws Exception{new Thread(null, new Solution(),"Main",1<<27).start();}

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

	public static int findGCD(int arr[], int n) { 	int result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result);return result; }

	static long power(long x, long y) { long temp; if( y == 0) return 1; temp = power(x, y/2)%1000000007;  if (y%2 == 0)  return (temp*temp)%1000000007;
        else{ if(y > 0) return (((x*temp)%1000000007)*temp)%1000000007; else return (((temp*temp)%1000000007)/x)%1000000007; } }

	static void sortbycolomn(long arr[][], int col)
    {
        Arrays.sort(arr, new Comparator<long[]>() {
        @Override
        public int compare(final long[] entry1,final long[] entry2) {
            if (entry1[col] > entry2[col])return 1;
            else return -1;
        }
        });
    }

	public void run()
    {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int t=in.nextInt();
        while(t--!=0){
            int h=in.nextInt();
            int n=in.nextInt();
            int[] arr=new int[n];
            for(int i=0;i<n;i++) arr[i]=in.nextInt();

            if(h==2 || h==1){
                w.println("0");
                continue;
            }
            else if(h==3 && n==3){
                w.println("0");
                continue;
            }
            else if(h==3 && n==2){
                if(arr[1]==1)
                    w.println("0");
                else
                    w.println("1");

                continue;
            }
            else if(n==1){
                w.println("0");
                continue;
            }

            int count=0;
            int pre=arr[0];
            int flag=0;
            int i=0;
            for(i=1;i<n-1;){
                if(pre-arr[i]==1){
                    if(arr[i+1]==pre-2){
                        pre=arr[i+1];
                        flag=2;
                        i+=2;
                    }
                    else{
                        pre=pre-2;
                        i++;
                        flag=0;
                        count++;
                    }
                }
                else{
                    pre=arr[i]+1;
                }
            }

            if(i==n-1 && pre-arr[n-1]!=2 && arr[n-1]!=1)
                count++;

            w.println(count);

        }

        w.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class Solution implements Runnable
{
	static class InputReader
	{
		private InputStream stream;private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public InputReader(InputStream stream){this.stream = stream;}
		public int read(){if (numChars==-1) throw new InputMismatchException();if (curChar >= numChars){curChar = 0;try{numChars = stream.read(buf);}catch (IOException e){throw new InputMismatchException();	}if(numChars <= 0)return -1;}return buf[curChar++];}
     	public String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
		public int nextInt(){int c = read();	while(isSpaceChar(c))c = read();	int sgn = 1; if (c == '-'){sgn = -1;c = read();	}int res = 0;do{if(c<'0'||c>'9') throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
        public long nextLong(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}long res = 0;do{if (c < '0' || c > '9')throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
		public double nextDouble(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}double res = 0;while (!isSpaceChar(c) && c != '.'){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')
		throw new InputMismatchException();res *= 10;res += c - '0';c = read();}if (c == '.'){c = read();double m = 1;while (!isSpaceChar(c)){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')throw new InputMismatchException();m /= 10;res += (c - '0') * m;c = read();}}return res * sgn;}
        public String readString(){int c = read();while (isSpaceChar(c))c = read();StringBuilder res = new StringBuilder();do{res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
		public boolean isSpaceChar(int c){if (filter != null)return filter.isSpaceChar(c);return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;}
		public String next(){return readString();}
        public interface SpaceCharFilter{public boolean isSpaceChar(int ch);}
	}

	public static void main(String args[]) throws Exception{new Thread(null, new Solution(),"Main",1<<27).start();}

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

	public static int findGCD(int arr[], int n) { 	int result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result);return result; }

	static long power(long x, long y) { long temp; if( y == 0) return 1; temp = power(x, y/2)%1000000007;  if (y%2 == 0)  return (temp*temp)%1000000007;
        else{ if(y > 0) return (((x*temp)%1000000007)*temp)%1000000007; else return (((temp*temp)%1000000007)/x)%1000000007; } }

	static void sortbycolomn(long arr[][], int col)
    {
        Arrays.sort(arr, new Comparator<long[]>() {
        @Override
        public int compare(final long[] entry1,final long[] entry2) {
            if (entry1[col] > entry2[col])return 1;
            else return -1;
        }
        });
    }

	public void run()
    {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int t=in.nextInt();
        while(t--!=0){
            int h=in.nextInt();
            int n=in.nextInt();
            int[] arr=new int[n];
            for(int i=0;i<n;i++) arr[i]=in.nextInt();

            if(h==2 || h==1){
                w.println("0");
                continue;
            }
            else if(h==3 && n==3){
                w.println("0");
                continue;
            }

            int count=0;
            int pre=arr[0];
            int flag=0;

            for(int i=1;i<n-1;){
                if(pre-arr[i]==1){
                    if(arr[i+1]==pre-2){
                        pre=arr[i+1];
                        flag=2;
                        i+=2;
                    }
                    else{
                        pre=pre-2;
                        i++;
                        flag=1;
                        count++;
                    }
                }
                else{
                    pre=arr[i]+1;
                }
            }
            if(flag==0 && n!=1 && arr[0]-arr[1]!=2)
                count++;
            else if(flag==1 && pre!=2)
                count++;

            w.println(count);

        }

        w.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class Solution implements Runnable
{
	static class InputReader
	{
		private InputStream stream;private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public InputReader(InputStream stream){this.stream = stream;}
		public int read(){if (numChars==-1) throw new InputMismatchException();if (curChar >= numChars){curChar = 0;try{numChars = stream.read(buf);}catch (IOException e){throw new InputMismatchException();	}if(numChars <= 0)return -1;}return buf[curChar++];}
     	public String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
		public int nextInt(){int c = read();	while(isSpaceChar(c))c = read();	int sgn = 1; if (c == '-'){sgn = -1;c = read();	}int res = 0;do{if(c<'0'||c>'9') throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
        public long nextLong(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}long res = 0;do{if (c < '0' || c > '9')throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
		public double nextDouble(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}double res = 0;while (!isSpaceChar(c) && c != '.'){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')
		throw new InputMismatchException();res *= 10;res += c - '0';c = read();}if (c == '.'){c = read();double m = 1;while (!isSpaceChar(c)){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')throw new InputMismatchException();m /= 10;res += (c - '0') * m;c = read();}}return res * sgn;}
        public String readString(){int c = read();while (isSpaceChar(c))c = read();StringBuilder res = new StringBuilder();do{res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
		public boolean isSpaceChar(int c){if (filter != null)return filter.isSpaceChar(c);return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;}
		public String next(){return readString();}
        public interface SpaceCharFilter{public boolean isSpaceChar(int ch);}
	}

	public static void main(String args[]) throws Exception{new Thread(null, new Solution(),"Main",1<<27).start();}

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

	public static int findGCD(int arr[], int n) { 	int result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result);return result; }

	static long power(long x, long y) { long temp; if( y == 0) return 1; temp = power(x, y/2)%1000000007;  if (y%2 == 0)  return (temp*temp)%1000000007;
        else{ if(y > 0) return (((x*temp)%1000000007)*temp)%1000000007; else return (((temp*temp)%1000000007)/x)%1000000007; } }

	static void sortbycolomn(long arr[][], int col)
    {
        Arrays.sort(arr, new Comparator<long[]>() {
        @Override
        public int compare(final long[] entry1,final long[] entry2) {
            if (entry1[col] > entry2[col])return 1;
            else return -1;
        }
        });
    }

	public void run()
    {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int t=in.nextInt();
        while(t--!=0){
            int h=in.nextInt();
            int n=in.nextInt();
            int[] arr=new int[n];
            for(int i=0;i<n;i++) arr[i]=in.nextInt();

            if(h==2 || h==1){
                w.println("0");
                continue;
            }
            else if(h==3 && n==3){
                w.println("0");
                continue;
            }

            int count=0;
            int pre=arr[0];
            int flag=0;

            for(int i=1;i<n-1;){
                if(pre-arr[i]==1){
                    if(arr[i+1]==pre-2){
                        pre=arr[i+1];
                        flag=2;
                        i+=2;
                    }
                    else{
                        pre=pre-2;
                        i++;
                        flag=1;
                        count++;
                    }
                }
                else{
                    pre=arr[i]+1;
                }
            }
            if(flag==0 && arr[1]==pre-1)
                    count++;
            else if(flag==1 && pre!=2)
                count++;

            w.println(count);

        }

        w.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class Solution implements Runnable
{
	static class InputReader
	{
		private InputStream stream;private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public InputReader(InputStream stream){this.stream = stream;}
		public int read(){if (numChars==-1) throw new InputMismatchException();if (curChar >= numChars){curChar = 0;try{numChars = stream.read(buf);}catch (IOException e){throw new InputMismatchException();	}if(numChars <= 0)return -1;}return buf[curChar++];}
     	public String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
		public int nextInt(){int c = read();	while(isSpaceChar(c))c = read();	int sgn = 1; if (c == '-'){sgn = -1;c = read();	}int res = 0;do{if(c<'0'||c>'9') throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
        public long nextLong(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}long res = 0;do{if (c < '0' || c > '9')throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
		public double nextDouble(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}double res = 0;while (!isSpaceChar(c) && c != '.'){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')
		throw new InputMismatchException();res *= 10;res += c - '0';c = read();}if (c == '.'){c = read();double m = 1;while (!isSpaceChar(c)){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')throw new InputMismatchException();m /= 10;res += (c - '0') * m;c = read();}}return res * sgn;}
        public String readString(){int c = read();while (isSpaceChar(c))c = read();StringBuilder res = new StringBuilder();do{res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
		public boolean isSpaceChar(int c){if (filter != null)return filter.isSpaceChar(c);return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;}
		public String next(){return readString();}
        public interface SpaceCharFilter{public boolean isSpaceChar(int ch);}
	}

	public static void main(String args[]) throws Exception{new Thread(null, new Solution(),"Main",1<<27).start();}

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

	public static int findGCD(int arr[], int n) { 	int result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result);return result; }

	static long power(long x, long y) { long temp; if( y == 0) return 1; temp = power(x, y/2)%1000000007;  if (y%2 == 0)  return (temp*temp)%1000000007;
        else{ if(y > 0) return (((x*temp)%1000000007)*temp)%1000000007; else return (((temp*temp)%1000000007)/x)%1000000007; } }

	static void sortbycolomn(long arr[][], int col)
    {
        Arrays.sort(arr, new Comparator<long[]>() {
        @Override
        public int compare(final long[] entry1,final long[] entry2) {
            if (entry1[col] > entry2[col])return 1;
            else return -1;
        }
        });
    }

	public void run()
    {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int t=in.nextInt();
        while(t--!=0){
            int h=in.nextInt();
            int n=in.nextInt();
            int[] arr=new int[n];
            for(int i=0;i<n;i++) arr[i]=in.nextInt();

            if(h==2 || h==1){
                w.println("0");
                continue;
            }
            else if(h==3 && n==3){
                w.println("0");
                continue;
            }

            int count=0;
            int pre=arr[0];
            int flag=0;

            for(int i=1;i<n-1;){
                if(pre-arr[i]==1){
                    if(arr[i+1]==pre-2){
                        pre=arr[i+1];
                        flag=2;
                        i+=2;
                    }
                    else{
                        pre=pre-2;
                        i++;
                        flag=1;
                        count++;
                    }
                }
                else{
                    pre=arr[i]+1;
                }
            }
            if(flag==0 && n!=1 && arr[0]-arr[1]!=2 && arr[1]!=1)
                count++;
            else if(flag==1 && pre!=2)
                count++;

            w.println(count);

        }

        w.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class Solution implements Runnable
{
	static class InputReader
	{
		private InputStream stream;private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public InputReader(InputStream stream){this.stream = stream;}
		public int read(){if (numChars==-1) throw new InputMismatchException();if (curChar >= numChars){curChar = 0;try{numChars = stream.read(buf);}catch (IOException e){throw new InputMismatchException();	}if(numChars <= 0)return -1;}return buf[curChar++];}
     	public String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
		public int nextInt(){int c = read();	while(isSpaceChar(c))c = read();	int sgn = 1; if (c == '-'){sgn = -1;c = read();	}int res = 0;do{if(c<'0'||c>'9') throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
        public long nextLong(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}long res = 0;do{if (c < '0' || c > '9')throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
		public double nextDouble(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}double res = 0;while (!isSpaceChar(c) && c != '.'){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')
		throw new InputMismatchException();res *= 10;res += c - '0';c = read();}if (c == '.'){c = read();double m = 1;while (!isSpaceChar(c)){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')throw new InputMismatchException();m /= 10;res += (c - '0') * m;c = read();}}return res * sgn;}
        public String readString(){int c = read();while (isSpaceChar(c))c = read();StringBuilder res = new StringBuilder();do{res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
		public boolean isSpaceChar(int c){if (filter != null)return filter.isSpaceChar(c);return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;}
		public String next(){return readString();}
        public interface SpaceCharFilter{public boolean isSpaceChar(int ch);}
	}

	public static void main(String args[]) throws Exception{new Thread(null, new Solution(),"Main",1<<27).start();}

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

	public static int findGCD(int arr[], int n) { 	int result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result);return result; }

	static long power(long x, long y) { long temp; if( y == 0) return 1; temp = power(x, y/2)%1000000007;  if (y%2 == 0)  return (temp*temp)%1000000007;
        else{ if(y > 0) return (((x*temp)%1000000007)*temp)%1000000007; else return (((temp*temp)%1000000007)/x)%1000000007; } }

	static void sortbycolomn(long arr[][], int col)
    {
        Arrays.sort(arr, new Comparator<long[]>() {
        @Override
        public int compare(final long[] entry1,final long[] entry2) {
            if (entry1[col] > entry2[col])return 1;
            else return -1;
        }
        });
    }

	public void run()
    {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int t=in.nextInt();
        while(t--!=0){
            int h=in.nextInt();
            int n=in.nextInt();
            int[] arr=new int[n];
            for(int i=0;i<n;i++) arr[i]=in.nextInt();

            if(h==2 || h==1){
                w.println("0");
                continue;
            }
            else if(h==3 && n==3){
                w.println("0");
                continue;
            }
            else if(h==3 && n==2){
                if(arr[1]==1)
                    w.println("0");
                else
                    w.println("1");

                continue;
            }

            int count=0;
            int pre=arr[0];
            int flag=0;

            for(int i=1;i<n-1;){
                if(pre-arr[i]==1){
                    if(arr[i+1]==pre-2){
                        pre=arr[i+1];
                        flag=2;
                        i+=2;
                    }
                    else{
                        pre=pre-2;
                        i++;
                        flag=1;
                        count++;
                    }
                }
                else{
                    pre=arr[i]+1;
                }
            }

            if(flag==1 && pre!=2 && pre-arr[n-1]!=2)
                count++;

            w.println(count);

        }

        w.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class Solution implements Runnable
{
	static class InputReader
	{
		private InputStream stream;private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public InputReader(InputStream stream){this.stream = stream;}
		public int read(){if (numChars==-1) throw new InputMismatchException();if (curChar >= numChars){curChar = 0;try{numChars = stream.read(buf);}catch (IOException e){throw new InputMismatchException();	}if(numChars <= 0)return -1;}return buf[curChar++];}
     	public String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
		public int nextInt(){int c = read();	while(isSpaceChar(c))c = read();	int sgn = 1; if (c == '-'){sgn = -1;c = read();	}int res = 0;do{if(c<'0'||c>'9') throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
        public long nextLong(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}long res = 0;do{if (c < '0' || c > '9')throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
		public double nextDouble(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}double res = 0;while (!isSpaceChar(c) && c != '.'){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')
		throw new InputMismatchException();res *= 10;res += c - '0';c = read();}if (c == '.'){c = read();double m = 1;while (!isSpaceChar(c)){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')throw new InputMismatchException();m /= 10;res += (c - '0') * m;c = read();}}return res * sgn;}
        public String readString(){int c = read();while (isSpaceChar(c))c = read();StringBuilder res = new StringBuilder();do{res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
		public boolean isSpaceChar(int c){if (filter != null)return filter.isSpaceChar(c);return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;}
		public String next(){return readString();}
        public interface SpaceCharFilter{public boolean isSpaceChar(int ch);}
	}

	public static void main(String args[]) throws Exception{new Thread(null, new Solution(),"Main",1<<27).start();}

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

	public static int findGCD(int arr[], int n) { 	int result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result);return result; }

	static long power(long x, long y) { long temp; if( y == 0) return 1; temp = power(x, y/2)%1000000007;  if (y%2 == 0)  return (temp*temp)%1000000007;
        else{ if(y > 0) return (((x*temp)%1000000007)*temp)%1000000007; else return (((temp*temp)%1000000007)/x)%1000000007; } }

	static void sortbycolomn(long arr[][], int col)
    {
        Arrays.sort(arr, new Comparator<long[]>() {
        @Override
        public int compare(final long[] entry1,final long[] entry2) {
            if (entry1[col] > entry2[col])return 1;
            else return -1;
        }
        });
    }

	public void run()
    {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int t=in.nextInt();
        while(t--!=0){
            int h=in.nextInt();
            int n=in.nextInt();
            int[] arr=new int[n+1];
            for(int i=0;i<n;i++) arr[i]=in.nextInt();
            int count=0;
            for(int i=1;i<n;i++){
                if(arr[i]>arr[i+1]+1)   count++;
                else i++;
            }

            w.println(count);

        }

        w.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class Solution implements Runnable
{
	static class InputReader
	{
		private InputStream stream;private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public InputReader(InputStream stream){this.stream = stream;}
		public int read(){if (numChars==-1) throw new InputMismatchException();if (curChar >= numChars){curChar = 0;try{numChars = stream.read(buf);}catch (IOException e){throw new InputMismatchException();	}if(numChars <= 0)return -1;}return buf[curChar++];}
     	public String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
		public int nextInt(){int c = read();	while(isSpaceChar(c))c = read();	int sgn = 1; if (c == '-'){sgn = -1;c = read();	}int res = 0;do{if(c<'0'||c>'9') throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
        public long nextLong(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}long res = 0;do{if (c < '0' || c > '9')throw new InputMismatchException();res *= 10;res += c - '0';c = read();}while (!isSpaceChar(c));return res * sgn;}
		public double nextDouble(){int c = read();while (isSpaceChar(c))c = read();int sgn = 1;if (c == '-'){sgn = -1;c = read();}double res = 0;while (!isSpaceChar(c) && c != '.'){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')
		throw new InputMismatchException();res *= 10;res += c - '0';c = read();}if (c == '.'){c = read();double m = 1;while (!isSpaceChar(c)){if (c == 'e' || c == 'E')return res * Math.pow(10, nextInt());if (c < '0' || c > '9')throw new InputMismatchException();m /= 10;res += (c - '0') * m;c = read();}}return res * sgn;}
        public String readString(){int c = read();while (isSpaceChar(c))c = read();StringBuilder res = new StringBuilder();do{res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
		public boolean isSpaceChar(int c){if (filter != null)return filter.isSpaceChar(c);return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;}
		public String next(){return readString();}
        public interface SpaceCharFilter{public boolean isSpaceChar(int ch);}
	}

	public static void main(String args[]) throws Exception{new Thread(null, new Solution(),"Main",1<<27).start();}

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

	public static int findGCD(int arr[], int n) { 	int result = arr[0]; for (int i = 1; i < n; i++) result = gcd(arr[i], result);return result; }

	static long power(long x, long y) { long temp; if( y == 0) return 1; temp = power(x, y/2)%1000000007;  if (y%2 == 0)  return (temp*temp)%1000000007;
        else{ if(y > 0) return (((x*temp)%1000000007)*temp)%1000000007; else return (((temp*temp)%1000000007)/x)%1000000007; } }

	static void sortbycolomn(long arr[][], int col)
    {
        Arrays.sort(arr, new Comparator<long[]>() {
        @Override
        public int compare(final long[] entry1,final long[] entry2) {
            if (entry1[col] > entry2[col])return 1;
            else return -1;
        }
        });
    }

	public void run()
    {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        int t=in.nextInt();
        while(t--!=0){
            int h=in.nextInt();
            int n=in.nextInt();
            int[] arr=new int[n];
            for(int i=0;i<n;i++) arr[i]=in.nextInt();

            if(h==2 || h==1){
                w.println("0");
                continue;
            }
            else if(h==3 && n==3){
                w.println("0");
                continue;
            }

            int count=0;
            int pre=arr[0];
            int flag=0;

            for(int i=1;i<n-1;){
                if(pre-arr[i]==1){
                    if(arr[i+1]==pre-2){
                        pre=arr[i+1];
                        flag=2;
                        i+=2;
                    }
                    else{
                        pre=pre-2;
                        i++;
                        flag=1;
                        count++;
                    }
                }
                else{
                    pre=arr[i]+1;
                }
            }
            if(flag==0 && n!=1 && arr[0]-arr[1]==1)
                count++;
            else if(flag==1 && pre!=2)
                count++;

            w.println(count);

        }

        w.flush();
        w.close();
    }
}


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

public class TaskC {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int q = s.nextInt();
		while(q-- > 0) {
			int h = s.nextInt();
			int n = s.nextInt();
			ArrayList<Integer> plat = new ArrayList<Integer>();

			for(int i=0;i<n;i++) {
				plat.add(s.nextInt());
			}

			Collections.sort(plat);
			Collections.reverse(plat);
			int buy = 0;
			plat.add(0);

			for(int i=1;i<n;i++) {
				int curr = plat.get(i);
				int next = plat.get(i+1);

				int dif = curr - next;

				if(dif == 1) {
					i++;
					continue;
				} else {
					buy++;
				}
			}

			System.out.println(buy);
		}
	}
}


import java.util.Scanner;

public class TaskC {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int q = s.nextInt();
		while(q-- > 0) {
			int h = s.nextInt();
			int n = s.nextInt();
			int[] platforms = new int[h+1];
			platforms[0] = 1;

			for(int i=0;i<n;i++) {
				platforms[s.nextInt()] = 1;
			}

			int pos = h;
			int buy = 0;

			while(pos > 0) {
				if(platforms[pos-1] == 0) {
					pos -= 1;
					continue;
				} else {
					if(pos - 2 >= 0 && platforms[pos-2] == 1) {
						pos -= 2;
						continue;
					} else {
						if(pos - 2 >= 0) {
							buy++;
							pos -= 2;
						} else {
							break;
						}
					}
				}
			}

			System.out.println(buy);
		}
	}
}


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

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int q = in.nextInt();
            for (int iter = 0; iter < q; iter++) {
                int h = in.nextInt();
                int N = in.nextInt();
                int[] arr = new int[N];
                for (int i = 0; i < N; i++) {
                    arr[i] = in.nextInt();
                }
                int cnt = 0;
                for (int i = 2; i < N; i++) {
                    if (arr[i] != arr[i - 1] - 1) {
                        cnt++;
                    }
                }
                out.println(cnt);
            }

        }

    }

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

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

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

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

    }
}


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

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int q = in.nextInt();
            for (int iter = 0; iter < q; iter++) {
                int h = in.nextInt();
                int N = in.nextInt();
                int[] arr = new int[N + 1];
                for (int i = 0; i < N; i++) {
                    arr[i] = in.nextInt();
                }
                int land = 0;
                int cnt = 0;
                while (land < N) {
                    if (land == N - 1) {
                        break;
                    }
                    if (arr[land + 1] - 1 != arr[land + 2]) {
                        land += 1;
                        cnt++;
                    } else {
                        land += 2;
                    }
                }
                out.println(cnt);
            }

        }

    }

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

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

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

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

    }
}


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

public class C {
	public class RevInt implements Comparable<RevInt>{
		public int x;

		public RevInt(int x) {
			this.x = x;
		}

		public int compareTo(RevInt r) {
			if(this.x < r.x) {
				return 1;
			} else if(this.x > r.x) {
				return -1;
			}
			return 0;
		}

		public boolean equals(RevInt r) {
			return this.x == r.x;
		}

		public boolean equals(Object o) {
			RevInt r = (RevInt)o;
			return equals(r);
		}
	}

	public void realMain() throws Exception {

		BufferedReader fin = new BufferedReader(new InputStreamReader(System.in), 1000000);

		String in = fin.readLine();

		String[] ar = in.split(" ");

		int Q = Integer.parseInt(ar[0]);

	for(int q = 0; q < Q; q++) {
		int ret2 = 0;
		boolean dig2 = false;
		for (int ch = 0; (ch = fin.read()) != -1; ) {
        		if (ch >= '0' && ch <= '9') {
            			dig2 = true;
           			ret2 = ret2 * 10 + ch - '0';
        		} else if (dig2) break;
    		}

		int h = ret2;

		ret2 = 0;
		dig2 = false;
		for (int ch = 0; (ch = fin.read()) != -1; ) {
        		if (ch >= '0' && ch <= '9') {
            			dig2 = true;
           			ret2 = ret2 * 10 + ch - '0';
        		} else if (dig2) break;
    		}

		int n = ret2;

		//boolean[] out = new boolean[h + 1];

		int[] out = new int[n];

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

		for(int i = 0; i < n; i++) {
			int ret = 0;
			boolean dig = false;
			for (int ch = 0; (ch = fin.read()) != -1; ) {
        			if (ch >= '0' && ch <= '9') {
            				dig = true;
           				ret = ret * 10 + ch - '0';
        			} else if (dig) break;
    			}

			out[i] = ret;
			pq.add(new RevInt(ret));

		}

		int ans = 0;

		int addedtoout = -1;

		while(pq.size() > 0) {
			int cur = pq.poll().x;
			boolean hasminus1 = pq.contains(new RevInt(cur - 1));
			boolean hasminus2 = pq.contains(new RevInt(cur - 2));
			if(cur <= 2) {
				while(pq.size() > 0) {
					pq.poll();
				}
				continue;
			}

			if(hasminus1 && hasminus2) {
				pq.poll();
			}

			if(hasminus1 && !hasminus2) {
				ans++;
				pq.poll();
				pq.add(new RevInt(cur - 2));
			}

			if(!hasminus1 && !hasminus2) {
				if(pq.size() > 0) {
					int nextout = pq.peek().x;
					pq.add(new RevInt(nextout + 1));
				}
			}

			if(!hasminus1 && hasminus2) {
				pq.add(new RevInt(cur - 1));
			}

		}

	/*	for(int i = 0; i < n - 2; i++) {
			if(out[i] == 1 + out[i + 1] && out[i + 1] != 1 + out[i + 2]) {
				ans++;
				pq.add(out[i] - 2);
			} else {
				if(addedtoout ==
		}
*/
		System.out.println(ans);

	}

	}

	public static void main(String[] args) throws Exception {
		C c = new C();
		c.realMain();
	}
}


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

public class C {
	public class RevInt implements Comparable<RevInt>{
		public int x;

		public RevInt(int x) {
			this.x = x;
		}

		public int compareTo(RevInt r) {
			if(this.x < r.x) {
				return 1;
			} else if(this.x > r.x) {
				return -1;
			}
			return 0;
		}

		public boolean equals(RevInt r) {
			return this.x == r.x;
		}

		public boolean equals(Object o) {
			RevInt r = (RevInt)o;
			return equals(r);
		}
	}

	public void realMain() throws Exception {

		BufferedReader fin = new BufferedReader(new InputStreamReader(System.in), 1000000);

		String in = fin.readLine();

		String[] ar = in.split(" ");

		int Q = Integer.parseInt(ar[0]);

	for(int q = 0; q < Q; q++) {
		int ret2 = 0;
		boolean dig2 = false;
		for (int ch = 0; (ch = fin.read()) != -1; ) {
        		if (ch >= '0' && ch <= '9') {
            			dig2 = true;
           			ret2 = ret2 * 10 + ch - '0';
        		} else if (dig2) break;
    		}

		int h = ret2;

		ret2 = 0;
		dig2 = false;
		for (int ch = 0; (ch = fin.read()) != -1; ) {
        		if (ch >= '0' && ch <= '9') {
            			dig2 = true;
           			ret2 = ret2 * 10 + ch - '0';
        		} else if (dig2) break;
    		}

		int n = ret2;

		//boolean[] out = new boolean[h + 1];

		int[] out = new int[n];

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

		for(int i = 0; i < n; i++) {
			int ret = 0;
			boolean dig = false;
			for (int ch = 0; (ch = fin.read()) != -1; ) {
        			if (ch >= '0' && ch <= '9') {
            				dig = true;
           				ret = ret * 10 + ch - '0';
        			} else if (dig) break;
    			}

			out[i] = ret;
			pq.add(new RevInt(ret));

		}

		int ans = 0;

		int addedtoout = -1;

		while(pq.size() > 0) {
			int cur = pq.poll().x;

			if(pq.size() == 0) {
				continue;
			}

			int tempremove = pq.poll().x;
			int temp2 = -3;
			if(pq.size() > 0) {
				temp2 = pq.peek().x;
			}

			boolean hasminus1 = tempremove == (cur - 1);
			boolean hasminus2 = temp2 == (cur - 2);

			if(cur <= 2) {
				while(pq.size() > 0) {
					pq.poll();
				}
				continue;
			}

			if(hasminus1 && hasminus2) {
				//pq.poll();
			}

			if(hasminus1 && !hasminus2) {
				ans++;
				//pq.poll();
				pq.add(new RevInt(cur - 2));
			}

			if(!hasminus1 && !hasminus2) {
				pq.add(new RevInt(tempremove));
				if(pq.size() > 0) {
					int nextout = pq.peek().x;
					pq.add(new RevInt(nextout + 1));
				}
			}

			if(!hasminus1 && hasminus2) {
				pq.add(new RevInt(tempremove));
				pq.add(new RevInt(cur - 1));
			}

		}

	/*	for(int i = 0; i < n - 2; i++) {
			if(out[i] == 1 + out[i + 1] && out[i + 1] != 1 + out[i + 2]) {
				ans++;
				pq.add(out[i] - 2);
			} else {
				if(addedtoout ==
		}
*/
		System.out.println(ans);

	}

	}

	public static void main(String[] args) throws Exception {
		C c = new C();
		c.realMain();
	}
}


import java.io.*;
import java.util.*;
public class Sol2{
	public static void main(String[] args) throws IOException{
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int q = sc.nextInt();
		while(q-->0) {
			int h = sc.nextInt();
			int n = sc.nextInt();
			int p[] = new int[n+1];
			for(int i=0; i<n; i++) {
				p[i] = sc.nextInt();
			}
			p[n] = 0;
			int tot = 0;
			int curr = h;
			for(int i=1; i<n; i++) {

				if(curr<=p[i]) {
					continue;
				}
				//System.out.println(curr + " curr");
				curr = p[i]+1;
				if(curr-p[i]==1) {
					if(p[i]-p[i+1]==1) {
						curr = p[i+1];
					}else {
						tot++;
						curr = curr-2;
					}
				}
			}
			System.out.println(tot);
		}
		out.close();
	}
	public static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

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

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

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

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

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

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


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

public class  Standard_Free2play
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out);

		int t=Integer.parseInt(br.readLine().trim());

		while(t-->0)
		{
			String str[]=br.readLine().trim().split(" ");
			int h=Integer.parseInt(str[0]);
			int n=Integer.parseInt(str[1]);

			int a[]=new int[n+1];
			str=br.readLine().trim().split(" ");
			for(int i=0;i<n;i++)
				a[i+1]=Integer.parseInt(str[i]);

			int b[]=new int[n+1];
			b[0]=1;
			for(int i=2;i<n+1;i++)
			{
				if(Math.abs(a[i]-a[i-1])==1)
				{
					b[i]=b[i-2];
				}
				else if(Math.abs(a[i]-a[i-1])==2)
				{
					b[i]=b[i-1];
				}
				else
				{
					b[i]=b[i-1]+1;
				}
			}
			/*int index=0;
			for(int x:b)
				System.out.println(x+" "+a[index++]);
			System.out.println();*/
			pw.println(b[n]);
		}
		pw.flush();
	}

}


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

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int t = in.nextInt();
        while (t-- > 0) {
            int h = in.nextInt();
            int n = in.nextInt();
            int p[] = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = in.nextInt();
            }
            if(n == 1){
                System.out.println(0);
                continue;
            }
            int pos = p[1] + 1;
            int dokup = 0;
            for (int i = 1; i < n; i++) {
                if (i == n - 1) {
                    if (pos != p[i]) {
                        if (pos > 2) dokup++;
                    }
                    break;
                }
                if (pos == p[i]) {
                    pos = p[i+1] + 1;
                }else{
                    if (pos - p[i + 1] == 2) {
                        pos = p[i + 1];
                    } else {
                        dokup++;
                        pos = p[i + 1] + 1;
                    }
                }
            }
            System.out.println(dokup);
        }
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(f));
        }

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

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

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

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


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

inline int read() {
    int x = 0;
    int f = 0;
    char c;
    do {
        c = getchar();
        if(c == '-')
            f = 1;
    } while(c < '0' || c > '9');
    do {
        x = (x << 3) + (x << 1) + c - '0';
        c = getchar();
    } while(c >= '0' && c <= '9');
    return f ? -x : x;
}

inline void _write(int x) {
    if(x > 9)
        _write(x / 10);
    putchar(x % 10 + '0');
}

inline void write(int x) {
    if(x < 0) {
        putchar('-');
        x = -x;
    }
    _write(x);
    putchar('\n');
}

int n, I, x,len;
int a[400005];

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    n = read(), I = read();
    x=(8*I)/n;
    len=(1<<x);
    for(int i=1;i<=n;++i){
        a[i]=read();
    }
    //cout<<"len="<<len<<endl;

    sort(a+1,a+1+n);

    int l=1,r=1;
    int cnt=1;
    int ans=n-1;
    //printf("%d\n",ans);
    while(r<n){
        r++;
        cnt++;
        /*cout<<"l="<<l<<" r="<<r<<endl;
        cout<<a[r]<<" "<<a[l]<<endl;*/
        while(a[r]-a[l]>=len){//???
            l++;
            cnt--;
        }
        /*cout<<"l="<<l<<" r="<<r<<endl;
        for(int i=1;i<=n;++i){
            printf("%d%c",a[i]," \n"[i==n]);
        }*/
        ans=min(ans,n-cnt);
        //cout<<"ans="<<ans<<endl;
    }
    printf("%d\n",ans);
}


#include <bits/stdc++.h>
using namespace std;
int num[400005],tmp[400005],sum[400005];
const long long INF=0x3f3f3f3f3f3f3f3f;
long long poww(long long a,long long b)
{
    long long res=1;
    while(b)
    {
        if(b&1)
            res=res*a;
        a=a*a;
        if(a>=1e9+3)
            return INF;
        b>>=1;
        if(res>=1e9+3)
            return INF;
    }
    return res;
}
int main()
{
    int n,I;
    cin>>n>>I;
    for(int i=0;i<n;++i)
        cin>>num[i];
    //离散化计数
    for(int i=0;i<n;++i)
        tmp[i]=num[i];
    sort(tmp,tmp+n);
    int nnew=unique(tmp,tmp+n)-tmp;
    int maxk=(8*I)/n;
    long long Kmax=poww(2,maxk);
    if(nnew<=Kmax)
        cout<<0<<endl;
    else
    {
        int ans,minn=0;
        memset(sum,0,sizeof(sum));
        for(int i=0;i<n;++i)
            ++sum[lower_bound(tmp,tmp+nnew,num[i])-tmp];
        //sort(sum,sum+nnew);
        //for(int i=0;i<nnew;++i)
            //cout<<sum[i]<<endl;
        for(int i=0;i<Kmax;++i)
            minn+=sum[i];
        ans=n-minn;
        for(int i=Kmax;i<nnew;++i)
        {
            minn=minn-sum[i-Kmax]+sum[i];
            ans=min(ans,n-minn);
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

inline int read() {
    int x = 0;
    int f = 0;
    char c;
    do {
        c = getchar();
        if(c == '-')
            f = 1;
    } while(c < '0' || c > '9');
    do {
        x = (x << 3) + (x << 1) + c - '0';
        c = getchar();
    } while(c >= '0' && c <= '9');
    return f ? -x : x;
}

inline void _write(int x) {
    if(x > 9)
        _write(x / 10);
    putchar(x % 10 + '0');
}

inline void write(int x) {
    if(x < 0) {
        putchar('-');
        x = -x;
    }
    _write(x);
    putchar('\n');
}

int n, I, x, len;
int a[400005];

map<int, int> m;

int main() {
#ifdef Yinku
    freopen("Yinku.in", "r", stdin);
#endif // Yinku
    n = read(), I = read();
    x = (8 * I) / n;
    len = (1 << x);
    for(int i = 1; i <= n; ++i) {
        a[i] = read();
    }
    //cout<<"len="<<len<<endl;
    sort(a + 1, a + 1 + n);
    int l = 1, r = 1;
    m[a[1]]++;
    int cnt = 1;
    int cnt2=1;
    int ans = n - 1;
    while(r < n) {
        r++;
        int t = m[a[r]]++;
        cnt2++;
        if(t == 0)
            cnt++;
        while(cnt > len) {
            int tmp = m[a[l]]--;
            if(tmp == 1) {
                cnt--;
            }
            l++;
            cnt2--;
        }
        //cout<<"l="<<l<<" r="<<r<<endl;
        //cout<<"cnt="<<cnt<<endl;
        /*for(int i=1;i<=n;++i){
            printf("%d%c",a[i]," \n"[i==n]);
        }*/
        ans = min(ans, n - cnt2);
        //cout<<"ans="<<ans<<endl;
    }
    printf("%d\n", ans);
}


#include <bits/stdc++.h>
using namespace std;

const int MAXBUF = 1 << 20;
char buf[MAXBUF], *fh, *ft;
inline char gc() {
    if(fh == ft) {
        int l = fread(buf, 1, MAXBUF, stdin);
        ft = (fh = buf) + l;
    }
    return *fh++;
}

inline int read() {
    int x = 0;
    char c = getchar();
    for(; c < '0' || c > '9'; c = getchar())
        ;
    for(; c >= '0' && c <= '9'; c = getchar())
        x = (x << 3) + (x << 1) + c - '0';
    return x ;
}

int num[400005],tmp[400005],sum[400005];
const long long INF=0x3f3f3f3f3f3f3f3f;
long long poww(long long a,long long b)
{
    long long res=1;
    while(b)
    {
        if(a>=1e9+3)
            return INF;
        if(b&1)
            res=res*a;
        if(res>=1e9+3)
            return INF;
        a=a*a;
        b>>=1;
    }
    return res;
}
int main()
{
    int n=read(),I=read();
    for(int i=0;i<n;++i)
        num[i]=read();
    //离散化计数
    for(int i=0;i<n;++i)
        tmp[i]=num[i];
    sort(tmp,tmp+n);
    int nnew=unique(tmp,tmp+n)-tmp;
    int maxk=(8*I)/n;
    long long Kmax=poww(2,maxk);
    if(nnew<=Kmax)
        cout<<0<<endl;
    else
    {
        int ans,minn=0;
        memset(sum,0,sizeof(sum));
        for(int i=0;i<n;++i)
            ++sum[lower_bound(tmp,tmp+nnew,num[i])-tmp];
        //sort(sum,sum+nnew);
        //for(int i=0;i<nnew;++i)
            //cout<<sum[i]<<endl;
        for(int i=0;i<Kmax;++i)
            minn+=sum[i];
        ans=n-minn;
        for(int i=Kmax;i<nnew;++i)
        {
            minn=minn-sum[i-Kmax]+sum[i];
            ans=min(ans,n-minn);
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define   crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return fastpower((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
}
ll GCD(ll A, ll B) {
    if(B==0)
        return A;
    else
        return GCD(B, A % B);
}
bool vowl(char c)
{
  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}
ll modInverse(ll A,ll M)// when M is prime
{
    return fastpower(A,M-2,M);
}
void sieve(ll N) {
        bool isPrime[N+1];
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(ll i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(ll j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
vector<ll> factorize(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}

int main()
{
	crap;
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	    #endif
	ll n,k;
	cin>>n>>k;
	ll t=1;

	int h=(k*8)/n;
	for(int i=0;i<min(20,h);i++)
	{
t*=2;

	}
	int cont=0;

	map<ll,ll>m;
	f(i,n)
	{
		ll y;
		cin>>y;
		if(y==0)
			cont++;

m[y]++;

	}
	vll v;
	if(cont>0)
		v.pb(cont);

	for(auto it=m.begin();it!=m.end();it++)
	{
v.pb(it->second);

	}

	if(t>=v.size())
		cout<<"0"<<endl;
	else
	{
		ll d=1000000000;
		for(int i=0;i+t<=v.size();i++)
		{
			ll cont=0;

			for(int j=i;j<(i+t);j++)
			{
cont+=v[i];

			}
			d=min(d,n-cont);

		}
		cout<<d<<endl;

	}
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define   crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return fastpower((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
}
ll GCD(ll A, ll B) {
    if(B==0)
        return A;
    else
        return GCD(B, A % B);
}
bool vowl(char c)
{
  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}
ll modInverse(ll A,ll M)// when M is prime
{
    return fastpower(A,M-2,M);
}
void sieve(ll N) {
        bool isPrime[N+1];
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(ll i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(ll j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
vector<ll> factorize(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}

int main()
{
	crap;
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	    #endif
	ll n,k;
	cin>>n>>k;
	ll t=1;

	int h=(k*8)/n;
	for(int i=0;i<min(20,h);i++)
	{
t*=2;

	}
	map<ll,ll>m;
	f(i,n)
	{
		ll y;
		cin>>y;

m[y]++;

	}
	vll v;

	for(auto it=m.begin();it!=m.end();it++)
	{
v.pb(it->second);

	}

	if(t>=v.size())
		cout<<"0"<<endl;
	else
	{ll d=1000000000;
		for(int i=0;i+t<=v.size();i++)
		{
			ll cont=0;

			for(int j=i;j<=(i+t)-1;j++)
			{
cont+=v[i];

			}
			d=min(d,n-cont);

		}
		cout<<d<<endl;

	}
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define   crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return fastpower((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
}
ll GCD(ll A, ll B) {
    if(B==0)
        return A;
    else
        return GCD(B, A % B);
}
bool vowl(char c)
{
  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}
ll modInverse(ll A,ll M)// when M is prime
{
    return fastpower(A,M-2,M);
}
void sieve(ll N) {
        bool isPrime[N+1];
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(ll i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(ll j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
vector<ll> factorize(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}

int main()
{
	crap;
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	    #endif
	ll n,k;
	cin>>n>>k;
	ll t=1;

	ll h=(k*8)/n;
	for(int i=0;i<min(20,h);i++)
	{
t*=2;

	}
	map<ll,ll>m;
	f(i,n)
	{
		ll y;
		cin>>y;

m[y]++;

	}
	vll v;

	for(auto it=m.begin();it!=m.end();it++)
	{
v.pb(it->second);

	}

	if(t>=v.size())
		cout<<"0"<<endl;
	else
	{ll d=1000000000;
		for(int i=0;i+t<=v.size();i++)
		{
			ll cont=0;

			for(int j=i;j<=(i+t)-1;j++)
			{
cont+=v[i];

			}
			d=min(d,n-cont);

		}
		cout<<d<<endl;

	}
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define   crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return fastpower((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
}
ll GCD(ll A, ll B) {
    if(B==0)
        return A;
    else
        return GCD(B, A % B);
}
bool vowl(char c)
{
  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}
ll modInverse(ll A,ll M)// when M is prime
{
    return fastpower(A,M-2,M);
}
void sieve(ll N) {
        bool isPrime[N+1];
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(ll i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(ll j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
vector<ll> factorize(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}

int main()
{
	crap;
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	    #endif
	ll n,k;
	cin>>n>>k;
	ll t=1;

	int h=(k*8)/n;
	for(int i=0;i<min(20,h);i++)
	{
t*=2;

	}
	map<ll,ll>m;
	f(i,n)
	{
		ll y;
		cin>>y;

m[y]++;

	}
	vll v;

	for(auto it=m.begin();it!=m.end();it++)
	{
v.pb(it->second);

	}

	if(t>=v.size())
		cout<<"0"<<endl;
	else
	{
		ll d=1000000000;
		for(int i=0;i+t<=v.size();i++)
		{
			ll cont=0;

			for(int j=i;j<(i+t);j++)
			{
cont+=v[i];

			}
			d=min(d,n-cont);

		}
		cout<<d<<endl;

	}
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define   crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return fastpower((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
}
ll GCD(ll A, ll B) {
    if(B==0)
        return A;
    else
        return GCD(B, A % B);
}
bool vowl(char c)
{
  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}
ll modInverse(ll A,ll M)// when M is prime
{
    return fastpower(A,M-2,M);
}
void sieve(ll N) {
        bool isPrime[N+1];
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(ll i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(ll j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
vector<ll> factorize(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}

int main()
{
	crap;
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	    #endif
	ll n,k;
	cin>>n>>k;
	ll t=1;

	ll h=(k*8)/n;
	while(h--)
	{
t*=2;
if(t>=n)
break;

	}
	map<ll,ll>m;
	f(i,n)
	{
		ll y;
		cin>>y;

m[y]++;

	}
	vll v;

	for(auto it=m.begin();it!=m.end();it++)
	{
v.pb(it->second);

	}

	if(t>=v.size())
		cout<<"0"<<endl;
	else
	{ll d=1000000000;
		for(int i=0;i+t<v.size();i++)
		{
			ll cont=0;

			for(int j=i;j<=(i+t)-1;j++)
			{
cont+=v[i];

			}
			d=min(d,n-cont);

		}
		cout<<d<<endl;

	}
	return 0;
}