import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p);
		int ans = -1;
		int sub = 100;
		if(n==0) ans = x;
		else if(x<p[0]) ans=x;
		else if(x>p[n-1]) ans=x;
		else {
			if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			}
		}
		if(ans==-1) {
			if(Math.abs((p[0]-1)-x)<=Math.abs((p[n-1]+1)-x)) {
				ans = p[0]-1;
			}
			else ans =p[n-1]+1;
		}
		System.out.println(ans);
	 }
} import java.util.*; util.* java import java.math.RoundingMode; RoundingMode java.math import java.math.BigDecimal; BigDecimal java.math public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p);
		int ans = -1;
		int sub = 100;
		if(n==0) ans = x;
		else if(x<p[0]) ans=x;
		else if(x>p[n-1]) ans=x;
		else {
			if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			}
		}
		if(ans==-1) {
			if(Math.abs((p[0]-1)-x)<=Math.abs((p[n-1]+1)-x)) {
				ans = p[0]-1;
			}
			else ans =p[n-1]+1;
		}
		System.out.println(ans);
	 }
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p);
		int ans = -1;
		int sub = 100;
		if(n==0) ans = x;
		else if(x<p[0]) ans=x;
		else if(x>p[n-1]) ans=x;
		else {
			if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			}
		}
		if(ans==-1) {
			if(Math.abs((p[0]-1)-x)<=Math.abs((p[n-1]+1)-x)) {
				ans = p[0]-1;
			}
			else ans =p[n-1]+1;
		}
		System.out.println(ans);
	 } main {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p);
		int ans = -1;
		int sub = 100;
		if(n==0) ans = x;
		else if(x<p[0]) ans=x;
		else if(x>p[n-1]) ans=x;
		else {
			if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			}
		}
		if(ans==-1) {
			if(Math.abs((p[0]-1)-x)<=Math.abs((p[n-1]+1)-x)) {
				ans = p[0]-1;
			}
			else ans =p[n-1]+1;
		}
		System.out.println(ans);
	 } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] p = new int[n]; p new int[n] n for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			p[i] = sc.nextInt();
		} {
			p[i] = sc.nextInt();
		} p[i] = sc.nextInt() p[i] p i sc.nextInt() sc.nextInt sc Arrays.sort(p) Arrays.sort Arrays p int ans = -1; ans -1 1 int sub = 100; sub 100 if(n==0) ans = x;
		else if(x<p[0]) ans=x;
		else if(x>p[n-1]) ans=x;
		else {
			if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			}
		} n==0 n 0 ans = x ans x if(x<p[0]) ans=x;
		else if(x>p[n-1]) ans=x;
		else {
			if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			}
		} x<p[0] x p[0] p 0 ans=x ans x if(x>p[n-1]) ans=x;
		else {
			if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			}
		} x>p[n-1] x p[n-1] p n-1 n 1 ans=x ans x {
			if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			}
		} if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			} x==p[0] x p[0] p 0 ans=x-1 ans x-1 x 1 if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			} p[n-1]==x&&p[n-1]-p[n-2]<=1 p[n-1]==x p[n-1] p n-1 n 1 x p[n-1]-p[n-2]<=1 p[n-1]-p[n-2] p[n-1] p n-1 n 1 p[n-2] p n-2 n 2 1 ans=x+1 ans x+1 x 1 {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			} for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				} int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i++ i++ i {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				} {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				} int left = p[i]; left p[i] p i int right = p[i+1]; right p[i+1] p i+1 i 1 if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						} right>x&&left<x right>x right x left<x left x ans = x ans x if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						} left>=x&&sub>left+1-x left>=x left x sub>left+1-x sub left+1-x left+1 left 1 x {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						} if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							} right-left>1 right-left right left 1 {
								ans=left+1;
								sub = ans-x;
							} ans=left+1 ans left+1 left 1 sub = ans-x sub ans-x ans x if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						} left>=x&&sub<left+1-x left>=x left x sub<left+1-x sub left+1-x left+1 left 1 x {
							break;
						} break; if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						} right<=x&&sub>x-(right-1) right<=x right x sub>x-(right-1) sub x-(right-1) x (right-1) right 1 {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						} if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							} right-left>1 right-left right left 1 {
								ans=right-1;
								sub = x-ans;
							} ans=right-1 ans right-1 right 1 sub = x-ans sub x-ans x ans if(right<=x&&sub<x-(right-1)) {
							break;
						} right<=x&&sub<x-(right-1) right<=x right x sub<x-(right-1) sub x-(right-1) x (right-1) right 1 {
							break;
						} break; if(ans==-1) {
			if(Math.abs((p[0]-1)-x)<=Math.abs((p[n-1]+1)-x)) {
				ans = p[0]-1;
			}
			else ans =p[n-1]+1;
		} ans==-1 ans -1 1 {
			if(Math.abs((p[0]-1)-x)<=Math.abs((p[n-1]+1)-x)) {
				ans = p[0]-1;
			}
			else ans =p[n-1]+1;
		} if(Math.abs((p[0]-1)-x)<=Math.abs((p[n-1]+1)-x)) {
				ans = p[0]-1;
			}
			else ans =p[n-1]+1; Math.abs((p[0]-1)-x)<=Math.abs((p[n-1]+1)-x) Math.abs((p[0]-1)-x) Math.abs Math (p[0]-1)-x (p[0]-1) p[0] p 0 1 x Math.abs((p[n-1]+1)-x) Math.abs Math (p[n-1]+1)-x (p[n-1]+1) p[n-1] p n-1 n 1 1 x {
				ans = p[0]-1;
			} ans = p[0]-1 ans p[0]-1 p[0] p 0 1 ans =p[n-1]+1 ans p[n-1]+1 p[n-1] p n-1 n 1 1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p);
		int ans = -1;
		int sub = 100;
		if(n==0) ans = x;
		else if(x<p[0]) ans=x;
		else if(x>p[n-1]) ans=x;
		else {
			if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			}
		}
		if(ans==-1) {
			if(Math.abs((p[0]-1)-x)<=Math.abs((p[n-1]+1)-x)) {
				ans = p[0]-1;
			}
			else ans =p[n-1]+1;
		}
		System.out.println(ans);
	 }
} public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p);
		int ans = -1;
		int sub = 100;
		if(n==0) ans = x;
		else if(x<p[0]) ans=x;
		else if(x>p[n-1]) ans=x;
		else {
			if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			}
		}
		if(ans==-1) {
			if(Math.abs((p[0]-1)-x)<=Math.abs((p[n-1]+1)-x)) {
				ans = p[0]-1;
			}
			else ans =p[n-1]+1;
		}
		System.out.println(ans);
	 }
} Main
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		Arrays.sort(p);
		int ans = -1;
		int sub = 100;
		if(n==0) ans = x;
		else if(x<p[0]) ans=x;
		else if(x>p[n-1]) ans=x;
		else {
			if(x==p[0]) ans=x-1;
			else if(p[n-1]==x&&p[n-1]-p[n-2]<=1) ans=x+1;
			else {
				for(int i = 0; i < n-1; i++) {
					int left = p[i];
					int right = p[i+1];
					if(right>x&&left<x) ans = x;
					else if(left>=x&&sub>left+1-x) {
							if(right-left>1) {
								ans=left+1;
								sub = ans-x;
							}
							
						}
						else if(left>=x&&sub<left+1-x) {
							break;
						}
						else if(right<=x&&sub>x-(right-1)) {
							if(right-left>1) {
								ans=right-1;
								sub = x-ans;
							}
							
						}
						else if(right<=x&&sub<x-(right-1)) {
							break;
						}
				}
			}
		}
		if(ans==-1) {
			if(Math.abs((p[0]-1)-x)<=Math.abs((p[n-1]+1)-x)) {
				ans = p[0]-1;
			}
			else ans =p[n-1]+1;
		}
		System.out.println(ans);
	 }
}