import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;

public class s1
{
    public static void main(String[] args) {
        new s1().solve();
    }
    long[]arr;
    public void solve()
    {
        PrintWriter out=new PrintWriter(System.out);
        int n=in.nextInt();
        int m=in.nextInt();
        int max=0;
        int min=Integer.MAX_VALUE;
        for(int i=0;i<n;i++)
        {
            int temp=in.nextInt();
            max=Math.max(temp, max);
            min=Math.min(min, temp);

        }
        if(min*2<=max)
        {
            for(int j=0;j<m;j++)
            {
                 int temp=in.nextInt();
                 if(temp<=max)
                 {
                     System.out.println(-1);
                     System.exit(0);
                 }
            }
            System.out.println(max);
        }
        else
        {
            for(int i=0;i<m;i++)
            {
                in.nextInt();
            }
            System.out.println("-1");
        }
        out.close();
    }

    FasterScanner in=new FasterScanner();

    public class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

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

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

        public String nextString() {
            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 long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

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

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


import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;

public class Solution
{
    public static void main(String[] args) {
        new Solution().solve();
    }
    long[]arr;
    public void solve()
    {
        PrintWriter out=new PrintWriter(System.out);
        int n=in.nextInt();
        int m=in.nextInt();
        int max=0;
        int min=Integer.MAX_VALUE;
        for(int i=0;i<n;i++)
        {
            int temp=in.nextInt();
            max=Math.max(temp, max);
            min=Math.min(min, temp);

        }
        if(min*2<=max)
        {

        }
        else
        {
            max=min*2;
        }
        for(int j=0;j<m;j++)
        {
             int temp=in.nextInt();
             if(temp<=max)
             {
                 System.out.println(-1);
                 System.exit(0);
             }
        }
        System.out.println(max);
        out.close();
    }

    FasterScanner in=new FasterScanner();

    public class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

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

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

        public String nextString() {
            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 long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

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

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

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

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


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

public class CF203A {

    public static void main(String[] args) throws IOException {
        BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
        String [] r = rdr.readLine().split(" ");
        int correct = Integer.parseInt(r[0]);
        int wrong = Integer.parseInt(r[1]);
        int [] right = new int [correct];
        int [] bad = new int [wrong];
        String [] input = rdr.readLine().split(" ");
        String [] input2 = rdr.readLine().split(" ");
        for(int i = 0; i < correct;i++)
            right[i] = Integer.parseInt(input[i]);
        for(int i = 0; i < wrong;i++)
            bad[i] = Integer.parseInt(input2[i]);
        Arrays.sort(right);
        Arrays.sort(bad);
        int v = right[correct-1];
        //System.out.println(right[0]+" "+bad[0]+" "+v);
        if(right[0]*2 > v) v = right[0]*2;
        if(bad[0] <= v) {
            System.out.println(-1);
            return;
        }
        System.out.println(v);
    }
}


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

public class CF203A{

    public static void main(String[] args) throws IOException {
        BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
        String [] r = rdr.readLine().split(" ");
        int correct = Integer.parseInt(r[0]);
        int wrong = Integer.parseInt(r[1]);
        int [] right = new int [correct];
        int [] bad = new int [wrong];
        String [] input = rdr.readLine().split(" ");
        String [] input2 = rdr.readLine().split(" ");
        for(int i = 0; i < correct;i++)
            right[i] = Integer.parseInt(input[i]);
        for(int i = 0; i < wrong;i++)
            bad[i] = Integer.parseInt(input2[i]);
        Arrays.sort(right);
        Arrays.sort(bad);
        int v = right[correct-1];
        //System.out.println(right[0]+" "+bad[0]+" "+v);
        if(right[0]*2 > v) v = right[0]*2;
        if(bad[0] <= v) {
            System.out.println(-1);
            return;
        }
        System.out.println(v);
    }
}


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

public class CF203A {

    public static void main(String[] args) throws IOException {
        BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in));
        String [] r = rdr.readLine().split(" ");
        int correct = Integer.parseInt(r[0]);
        int wrong = Integer.parseInt(r[1]);
        int [] right = new int [correct];
        int [] bad = new int [wrong];
        String [] input = rdr.readLine().split(" ");
        String [] input2 = rdr.readLine().split(" ");
        for(int i = 0; i < correct;i++)
            right[i] = Integer.parseInt(input[i]);
        for(int i = 0; i < wrong;i++)
            bad[i] = Integer.parseInt(input2[i]);
        Arrays.sort(right);
        Arrays.sort(bad);
        int v = right[correct-1];
        //System.out.println(right[0]+" "+bad[0]+" "+v);
        if(2*right[0] > v || bad[0] <= v) {
            System.out.println(-1);
            return;
        }
        System.out.println(v);
    }
}


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

public class A {
	FastScanner in;
	PrintWriter out;

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

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

		int[] b = new int[m];
		for (int i = 0; i < m; i++)
			b[i] = in.nextInt();

		Arrays.sort(a);
		Arrays.sort(b);

		int v = Math.max(1, Math.max(2 * a[0], a[n - 1]));
		if (v < b[0]) {
			out.print(v);
		} else {
			out.print(-1);
		}
	}

	public void run() {
		try {
			in = new FastScanner(System.in);
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] arg) {
		new A().run();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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


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

public class A {
	FastScanner in;
	PrintWriter out;

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

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

		int[] b = new int[m];
		for (int i = 0; i < m; i++)
			b[i] = in.nextInt();

		Arrays.sort(a);
		Arrays.sort(b);

		int v = Math.max(1, Math.max(2 * a[0], a[n - 1]));
		if (v < b[m - 1]) {
			out.print(v);
		} else {
			out.print(-1);
		}
	}

	public void run() {
		try {
			in = new FastScanner(System.in);
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] arg) {
		new A().run();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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


import java.util.*;
public class pa {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int arr []= new int[n];
        int wrong []= new int[m];
        for(int i=0;i<n;i++)
            {arr[i]=sc.nextInt();}
        for (int i = 0; i < wrong.length; i++) {
            wrong[i]=sc.nextInt();}
        int TL=Integer.MAX_VALUE;

        for (int j = 0; j < arr.length; j++) {
            int desired = arr[j];
            int count=0;
            for (int k = 0; k < arr.length; k++) {
                if(arr[k] >desired)
                    desired = 0;
                if(2*arr[k]<=desired){
                    count++;
                }
            }
            if(count >=1 && desired >0){
            for (int k = 0; k < wrong.length; k++) {
                if(wrong[k]<desired)
                {
                    desired=0;
                }
            }
            if(desired!=0){
            TL=Math.min(TL, desired);
            }
            }
        }

        if(TL == Integer.MAX_VALUE)
            System.out.println(-1);
        else
            System.out.println(TL);
        }
}


import java.util.*;
public class pa {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int arr []= new int[n];
        int wrong []= new int[m];
        for(int i=0;i<n;i++)
            {arr[i]=sc.nextInt();}
        for (int i = 0; i < wrong.length; i++) {
            wrong[i]=sc.nextInt();}
        int TL=Integer.MAX_VALUE;

        for (int j = 0; j < arr.length; j++) {
            int desired = arr[j];
            int count=0;
            for (int k = 0; k < arr.length; k++) {
                if(arr[k] >desired)
                    desired = 0;
                if(2*arr[k]<=desired){
                    count++;
                }
            }
            if(count >=1 && desired >0){
            for (int k = 0; k < wrong.length; k++) {
                if(wrong[k]<=desired)
                {
                    desired=0;
                }
            }
            if(desired!=0){
            TL=Math.min(TL, desired);
            }
            }
            desired = 2*arr[j];
            count=0;
            for (int k = 0; k < arr.length; k++) {
                if(arr[k] >desired)
                    desired = 0;
                if(2*arr[k]<=desired){
                    count++;
                }
            }
            if(count >=1 && desired >0){
            for (int k = 0; k < wrong.length; k++) {
                if(wrong[k]<=desired)
                {
                    desired=0;
                }
            }
            if(desired!=0){
            TL=Math.min(TL, desired);
            }
            }
        }

        if(TL == Integer.MAX_VALUE)
            System.out.println(-1);
        else
            System.out.println(TL);
        }
}


import java.util.*;
public class pa {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int arr []= new int[n];
        int wrong []= new int[m];
        for(int i=0;i<n;i++)
            {arr[i]=sc.nextInt();}
        for (int i = 0; i < wrong.length; i++) {
            wrong[i]=sc.nextInt();}
        int TL=Integer.MAX_VALUE;

        for (int j = 0; j < arr.length; j++) {
            int desired = arr[j];
            int count=0;
            for (int k = 0; k < arr.length; k++) {
                if(arr[k] >desired)
                    desired = 0;
                if(2*arr[k]<=desired){
                    count++;
                }
            }
            if(count >=1 && desired >0){
            for (int k = 0; k < wrong.length; k++) {
                if(wrong[k]<desired)
                {
                    desired=0;
                }
            }
            if(desired!=0){
            TL=Math.min(TL, desired);
            }
            }
            desired = 2*arr[j];
            count=0;
            for (int k = 0; k < arr.length; k++) {
                if(arr[k] >desired)
                    desired = 0;
                if(2*arr[k]<=desired){
                    count++;
                }
            }
            if(count >=1 && desired >0){
            for (int k = 0; k < wrong.length; k++) {
                if(wrong[k]<desired)
                {
                    desired=0;
                }
            }
            if(desired!=0){
            TL=Math.min(TL, desired);
            }
            }
        }

        if(TL == Integer.MAX_VALUE)
            System.out.println(-1);
        else
            System.out.println(TL);
        }
}


import java.util.*;
public class pa {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int arr []= new int[n];
		int wrong []= new int[m];
		for(int i=0;i<n;i++)
			{arr[i]=sc.nextInt();}
		for (int i = 0; i < wrong.length; i++) {
			wrong[i]=sc.nextInt();}
		int TL=Integer.MAX_VALUE;

		for (int j = 0; j < arr.length; j++) {
			int desired = arr[j];
			int count=0;
			for (int k = 0; k < arr.length; k++) {
				if(arr[k] >desired)
					desired = 0;
				if(2*arr[k]<=desired){
					count++;
				}
			}
			if(count >=1 && desired >0){
			for (int k = 0; k < wrong.length; k++) {
				if(wrong[k]<desired)
				{
					desired=0;
				}
			}
			if(desired!=0){
			TL=Math.min(TL, desired);
			}
			}
		}

		if(TL == Integer.MAX_VALUE)
			System.out.println(-1);
		else
			System.out.println(TL);
		}
}


import java.util.*;
public class pa {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int arr []= new int[n];
		int wrong []= new int[m];
		for(int i=0;i<n;i++)
			{arr[i]=sc.nextInt();}
		for (int i = 0; i < wrong.length; i++) {
			wrong[i]=sc.nextInt();}
		int TL=Integer.MAX_VALUE;

		for (int j = 0; j < arr.length; j++) {
			int desired = arr[j];
			int count=0;
			for (int k = 0; k < arr.length; k++) {
				if(arr[k] >desired)
					desired = 0;
				if(2*arr[k]<=desired){
					count++;
				}
			}
			if(count ==1 && desired >0){
			for (int k = 0; k < wrong.length; k++) {
				if(wrong[k]<desired)
				{
					desired=0;
				}
			}
			if(desired!=0){
			TL=Math.min(TL, desired);
			}
			}
		}

		if(TL == Integer.MAX_VALUE)
			System.out.println(-1);
		else
			System.out.println(TL);
		}
}


import java.util.*;
public class pa {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int arr []= new int[n];
		int wrong []= new int[m];
		for(int i=0;i<n;i++)
			{arr[i]=sc.nextInt();}
		for (int i = 0; i < wrong.length; i++) {
			wrong[i]=sc.nextInt();}
		int TL=Integer.MAX_VALUE;

		for (int j = 0; j < arr.length; j++) {
			int desired = arr[j];
			int count=0;
			for (int k = 0; k < arr.length; k++) {
				if(2*arr[k]<desired)
					count++;
			}
			if(count ==1){
			for (int k = 0; k < wrong.length; k++) {
				if(wrong[k]<desired)
				{
					desired=0;
				}
			}
			if(desired!=0){
			TL=Math.min(TL, desired);
			}
			}
		}

		if(TL == Integer.MAX_VALUE)
			System.out.println(-1);
		else
			System.out.println(TL);
		}
}


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

public class CF350A{

	private static InputStream stream;
	private static PrintWriter pw;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;

	private static void soln(){
		int n = nextInt();
		int m = nextInt();
		int[] a = nextIntArray(n);
		int[] b = nextIntArray(m);
		int mina = Integer.MAX_VALUE;
		int minb = Integer.MAX_VALUE;
		int maxa = Integer.MIN_VALUE;

		for (int i=0; i<n; i++) {
			if(a[i] > maxa)
				maxa = a[i];
			if(a[i] < mina)
				mina = a[i];
		}

		for (int i=0; i<m; i++) {
			if(b[i] < minb)
				minb = b[i];
		}

		if(Math.max(2*mina,maxa) < minb)
			pw.println(Math.max(2*mina,maxa));
		else
			pw.println("-1");
	}

	public static void main(String[] args){
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		soln();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

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

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

	private static 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++];
	}

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

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

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

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

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

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

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

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main{

    static class FastScanner{
        StringTokenizer st;
        BufferedReader s;

        public FastScanner(){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader(new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }
        }

    }

    public static void main(String[] args) throws IOException{
        FastScanner s = new FastScanner();
        PrintWriter ww = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = s.nextInt();
        int m = s.nextInt();
        int[] ar1 = new int[n];
        int[] ar2 = new int[m];

        for(int i=0;i<n;i++)
            ar1[i] = s.nextInt();

        for(int i=0;i<m;i++)
            ar2[i] = s.nextInt();

        Arrays.sort(ar1);
        Arrays.sort(ar2);

        int xx = ar2[0]-1;
        if(xx < ar1[n-1])
            ww.println(-1);
        else if(ar1[0]*2 > ar1[n-1])
            ww.println(-1);
        else
            ww.println(ar1[n-1]);
        ww.close();
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main{

    static class FastScanner{
        StringTokenizer st;
        BufferedReader s;

        public FastScanner(){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader(new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }
        }

    }

    public static void main(String[] args) throws IOException{
        FastScanner s = new FastScanner();
        PrintWriter ww = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = s.nextInt();
        int m = s.nextInt();
        int[] ar1 = new int[n];
        int[] ar2 = new int[m];

        for(int i=0;i<n;i++)
            ar1[i] = s.nextInt();

        for(int i=0;i<m;i++)
            ar2[i] = s.nextInt();

        Arrays.sort(ar1);
        Arrays.sort(ar2);

        int xx = ar2[0]-1;

        if(xx < ar1[n-1])
            ww.println(-1);
        else if(ar1[0]*2 > xx)
            ww.println(-1);
        else if(ar1[0]*2 < ar1[n-1])
            ww.println(ar1[n-1]);
        else
            ww.println(ar1[0]*2);
        ww.close();
    }
}


import java.util.*;
public class a350
{

		public static void main(String ar[])
		{
				Scanner ob=new Scanner(System.in);
				int n=ob.nextInt();
				int m=ob.nextInt();
				int arr[]=new int[n];
				int arr1[]=new int[m];
				for(int i=0;i<n;i++)
						arr[i]=ob.nextInt();
				for(int i=0;i<m;i++)
						arr1[i]=ob.nextInt();
				Arrays.sort(arr);
				Arrays.sort(arr1);
				int max=arr[n-1];
				int min=arr1[0];
				int v=arr[0];
				int ans=0;
				if(Math.max(2*v,max)<min)
						ans=Math.max(2*v,max);
				else
						ans=-1;
				System.out.println(ans);
		}
}


import java.util.*;
public class a350
{

		public static void main(String ar[])
		{
				Scanner ob=new Scanner(System.in);
				int n=ob.nextInt();
				int m=ob.nextInt();
				int arr[]=new int[n];
				int arr1[]=new int[m];
				for(int i=0;i<n;i++)
						arr[i]=ob.nextInt();
				for(int i=0;i<m;i++)
						arr1[i]=ob.nextInt();
				Arrays.sort(arr);
				Arrays.sort(arr1);
				int max=arr[n-1];
				int min=arr1[m-1];
				int check=0,ans=0;
				if(max>=min) ans=-1;
				else
				{
						for(int i=0;i<n;i++)
						{
								if(2*arr[i]<=max)
								{
										check=1;
										break;
								}
						}
						if(check==1) ans=max;
						else ans=-1;
				}
				System.out.println(ans);
		}
}


import java.util.*;
public class a350
{

		public static void main(String ar[])
		{
				Scanner ob=new Scanner(System.in);
				int n=ob.nextInt();
				int m=ob.nextInt();
				int arr[]=new int[n];
				int arr1[]=new int[m];
				for(int i=0;i<n;i++)
						arr[i]=ob.nextInt();
				for(int i=0;i<m;i++)
						arr1[i]=ob.nextInt();
				Arrays.sort(arr);
				Arrays.sort(arr1);
				int max=arr[n-1];
				int min=arr1[0];
				int check=0,ans=0;
				if(max>=min) ans=-1;
				else
				{
						for(int i=0;i<n;i++)
						{
								if(2*arr[i]<=max)
								{
										check=1;
										break;
								}
						}
						if(check==1) ans=max;
						else ans=-1;
				}
				System.out.println(ans);
		}
}


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

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Test {
	public static void main(String[] args) {

		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		// Scanner in = new Scanner(System.in);
		TA solver = new TA();
		solver.solve(1, in, out);
		out.close();

	}
}

class TA {

	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int m = in.nextInt();
		int i, j;

		int t = 0;
		int min, max, min1;
		t = in.nextInt();
		min = t;

		max = t;
		for (i = 1; i < n; i++) {
			t = in.nextInt();
			if (t > max)
				max = t;
			if (t < min)
				min = t;
		}
		t = in.nextInt();

		min1 = t;
		for (i = 1; i < m; i++) {
			t = in.nextInt();
			if (t < min1)
				min1 = t;
		}
		//out.println(min1);
		if (2*min >= min1 || max >= min1){
			out.println(-1);
		}else{
			int o;
			o = Math.max(max, 2*min);
			out.println(o);
		}
	}

	public class Pet {
		int f, s, s1;

		public Pet(int f, int s) {
			this.f = f;
			this.s = s;
			this.s1 = s - 2;

		}

		public String toString() {
			return f + " = " + s1 + "-" + s;

		}
	}

}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
		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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Test {
	public static void main(String[] args) {

		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		// Scanner in = new Scanner(System.in);
		TA solver = new TA();
		solver.solve(1, in, out);
		out.close();

	}
}

class TA {

	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int m = in.nextInt();
		int i, j;

		int t = 0;
		int min, max, min1;
		t = in.nextInt();
		min = t;

		max = t;
		for (i = 1; i < n; i++) {
			t = in.nextInt();
			if (t > max)
				max = t;
			if (t < min)
				min = t;
		}
		t = in.nextInt();

		min1 = t;
		for (i = 1; i < m; i++) {
			t = in.nextInt();
			if (t < min)
				min1 = t;
		}

		if (2*min >= min1 || max >= min1){
			out.println(-1);
		}else{
			int o;
			o = Math.max(max, 2*min);
			out.println(o);
		}
	}

	public class Pet {
		int f, s, s1;

		public Pet(int f, int s) {
			this.f = f;
			this.s = s;
			this.s1 = s - 2;

		}

		public String toString() {
			return f + " = " + s1 + "-" + s;

		}
	}

}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
		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.PrintStream;
import java.util.*;

public class Problem203A {
    public static void main(String[] args) {
        new Problem203A(new Scanner(System.in), System.out).solve();
    }

    private Scanner in;
    private PrintStream out;

    public Problem203A(Scanner in, PrintStream out) {
        this.out = out;
        this.in = in;
    }

    public void solve() {
        int n = in.nextInt();
        int m = in.nextInt();

        List<Integer> ac = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            ac.add(in.nextInt());
        }
        Collections.sort(ac);
        in.nextLine();

        List<Integer> wa = new ArrayList<>(m);
        for (int i = 0; i < m; i++) {
            wa.add(in.nextInt());
        }
        Collections.sort(wa);

        int tl = ac.get(n-1);
        int min = ac.get(0);
        int max = wa.get(0);

        while (2*min > tl && tl < max) {
            tl++;
        }
        if (2*min <= tl && tl < max) {
            out.println(tl);
        } else {
            out.println(-1);
        }
    }
}


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

public class Problem203A {
    public static void main(String[] args) {
        new Problem203A(new Scanner(System.in), System.out).solve();
    }

    private Scanner in;
    private PrintStream out;

    public Problem203A(Scanner in, PrintStream out) {
        this.out = out;
        this.in = in;
    }

    public void solve() {
        int n = in.nextInt();
        int m = in.nextInt();

        List<Integer> ac = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            ac.add(in.nextInt());
        }
        Collections.sort(ac);
        in.nextLine();

        List<Integer> wa = new ArrayList<>(m);
        for (int i = 0; i < m; i++) {
            wa.add(in.nextInt());
        }
        Collections.sort(wa);

        int tl = ac.get(n-1);
        int min = ac.get(0);
        int max = wa.get(0);

        if (2*min <= tl && tl < max) {
            out.println(tl);
        } else {
            out.println(-1);
        }
    }
}


import java.util.Scanner;

/**
 * Created by shereifhawary on 5/2/15.
 */
public class TL {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt(), m = scanner.nextInt(), start;

        int correctMin = Integer.MAX_VALUE, correctMax = Integer.MIN_VALUE, wrong = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int c = scanner.nextInt();
            correctMin = Math.min(correctMin, c);
            correctMax = Math.max(correctMax, c);
        }
        for (int i = 0; i < m; i++) {
            wrong = Math.min(wrong, scanner.nextInt());
        }

        start = correctMax;

        while (start < 2 * correctMin) {
            start++;
        }
        if (start < wrong) {
            System.out.println(start);
        } else {
            System.out.println(-1);
        }

    }
}


import java.util.Scanner;

/**
 * Created by shereifhawary on 5/2/15.
 */
public class TL {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt(), m = scanner.nextInt(), start;

        int correctMin = Integer.MAX_VALUE, correctMax = Integer.MIN_VALUE, wrong = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            int c = scanner.nextInt();
            correctMin = Math.min(correctMin, c);
            correctMax = Math.max(correctMax, c);
        }
        for (int i = 0; i < m; i++) {
            wrong = Math.min(wrong, scanner.nextInt());
        }

        start = correctMax;

        if (start > 2 * correctMin) {
            System.out.println(start);
        } else {
            while (start < 2 * correctMin) {
                start++;
            }
            if (start < wrong) {
                System.out.println(start);
            } else {
                System.out.println(-1);
            }
        }

    }
}


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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int []a = new int[n];
		int []b = new int[m];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		for (int i = 0; i < m; i++) {
			b[i] = in.nextInt();
		}
		Arrays.sort(a);
		Arrays.sort(b);
		int v = b[0] - 1;

		while (a[n - 1] <= v && a[0] * 2 <= v) {
			v--;
		}
                if (v == b[0] - 1) {
                    v = -2;
                }
		System.out.println(v + 1);
	}
}


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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int []a = new int[n];
		int []b = new int[m];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		for (int i = 0; i < m; i++) {
			b[i] = in.nextInt();
		}
		Arrays.sort(a); System.out.println(a[0]);
		Arrays.sort(b);System.out.println(b[0]);
		int v = b[0] - 1;
		if (a[n - 1] > v || a[0] * 2 > v) {
			v = -1;
		}
		System.out.println(v);
	}
}


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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int []a = new int[n];
		int []b = new int[m];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		for (int i = 0; i < m; i++) {
			b[i] = in.nextInt();
		}
		Arrays.sort(a);
		Arrays.sort(b);
		int v = b[0] - 1;
		if (a[n - 1] > v || a[0] * 2 > v) {
			v = -1;
		}
		System.out.println(v);
	}
}


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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int []a = new int[n];
		int []b = new int[m];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		for (int i = 0; i < m; i++) {
			b[i] = in.nextInt();
		}
		Arrays.sort(a);
		Arrays.sort(b);
		int v = b[0] - 1;

		while (a[n - 1] <= v || a[0] * 2 <= v) {
			v--;
		}
                if (v == b[0] - 1) {
                    v = -2;
                }
		System.out.println(v + 1);
	}
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sami;

import java.util.Scanner;

/**
 *
 * @author intel
 */
public class SAMI {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       Scanner sc= new Scanner(System.in);
       int n=sc.nextInt();
       int m=sc.nextInt();
    int min=1000,max=-1;
        for (int i = 0; i < n; i++) {
           int k=sc.nextInt();
           if(k<min)min=k;
           if(max<k)max=k;
        }
 int ans=Math.max(2*min,max);
        for (int i = 0; i < m; i++) {
           int k=sc.nextInt();
           if(k<=ans){
               System.out.println("-1");
               return;
           }

        }
        System.out.println(ans);
        // TODO code application logic here
    }
}


import java.util.Scanner;

/**
 *
 * @author intel
 */
public class SAMI {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       Scanner sc= new Scanner(System.in);
       int n=sc.nextInt();
       int m=sc.nextInt();
    int min=1000,max=-1;
        for (int i = 0; i < n; i++) {
           int k=sc.nextInt();
           if(k<min)min=k;
           if(max<k)max=k;
        }
 int ans=Math.max(2*min,max);
        for (int i = 0; i < m; i++) {
           int k=sc.nextInt();
           if(k<=ans){
               System.out.println("-1");
               return;
           }

        }
        System.out.println(ans);
        // TODO code application logic here
    }
}


import sun.security.util.BigInt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: AUtemuratov
 * Date: 07.04.14
 * Time: 15:43
 * To change this template use File | Settings | File Templates.
 */
public class Main {

    static int n,m;
    static int a[] = new int[111];
    static int b[] = new int[111];
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);

        StringTokenizer tk = new StringTokenizer(bf.readLine(), " ");
        n = Integer.parseInt(tk.nextToken());
        m = Integer.parseInt(tk.nextToken());

        tk = new StringTokenizer(bf.readLine(), " ");
        for (int i=1; i<=n; i++) {
            a[i] = Integer.parseInt(tk.nextToken());
        }

        tk = new StringTokenizer(bf.readLine(), " ");
        for (int i=1; i<=m; i++) {
            b[i] = Integer.parseInt(tk.nextToken());
        }

        Arrays.sort(a,1,n+1);
        Arrays.sort(b,1,m+1);
        int t = Math.max(a[1]*2,a[n]);
        if (t < b[1]) {
            pw.println(t);
        } else {
            pw.println(-1);
        }

        pw.close();
        }

}


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

/**
 * Created with IntelliJ IDEA.
 * User: AUtemuratov
 * Date: 9/26/13
 * Time: 4:59 PM
 * To change this template use File | Settings | File Templates.
 */
public class Kamni {
    public static boolean a[] = new boolean[111111];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n,m;
        int a[] = new int[111];
        int b[] = new int[111];

        n = in.nextInt();
        m = in.nextInt();
        int max=0;
        int min=11111;

        for (int i=1; i<=n; i++) {
            a[i] = in.nextInt();
            if (a[i]>max) {
                max = a[i];
            }
        }

        for (int i=1; i<=m; i++) {
            b[i] = in.nextInt();
            if (b[i]<min) {
                min = b[i];
            }
        }

        boolean ok = false;

        for (int i=1; i<=n; i++) {
            if (a[i]*2<=max && (min>max)) {
                ok = true;
            }
        }

        if (ok)
        System.out.println(max);
        else {
            System.out.println(-1);
        }

    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

/**
 *
 * @author ehab
 */
public class main {
  public static void main(String[] args) throws Exception{
      BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)) ;
      StringTokenizer s = new StringTokenizer(bf.readLine()) ;
      int n1 = Integer.parseInt(s.nextToken()) ;
      int n2 = Integer.parseInt(s.nextToken()) ;
      int co [] = new int [n1] ;
      int wo [] = new int [n2] ;
      s = new StringTokenizer(bf.readLine()) ;
      for(int i = 0 ; i < n1 ; i++)
          co[i] = Integer.parseInt(s.nextToken()) ;

     s = new StringTokenizer(bf.readLine()) ;
      for(int i = 0 ; i < n2 ; i++)
          wo[i] = Integer.parseInt(s.nextToken()) ;
      Arrays.sort(co);
      Arrays.sort(wo);
      co[0]  = 2 * co[0];
      Arrays.sort(co);
      if(wo[0] > co[n1-1] )
          System.out.println(co[n1-1]);
      else
          System.out.println(-1);

  }
}


import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Reader.init(System.in);
        int n = Reader.nextInt() ;
        int m = Reader.nextInt() ;
        int [] correct = new int [n] ;
        int [] wrong = new int [m] ;
        fill(correct);
        fill(wrong);
        Arrays.sort(correct);
        Arrays.sort(wrong);
        if (Math.max(correct[0]*2,correct[n-1])<wrong[0])
            System.out.println(Math.max(correct[0]*2,correct[n-1]));
        else
            System.out.println(-1);
    }

    public static void fill(int[] a) throws Exception {
        for (int i = 0; i < a.length; i++) {
            a[i] = Reader.nextInt();
        }
    }
 static void s(int[] cc) {
        for (int e = 0; e < cc.length; e++) {
            for (int q = e + 1; q < cc.length; q++) {
                if (cc[e] < cc[q]) {
                    int g = cc[e];
                    cc[e] = cc[q];
                    cc[q] = g;
                }
            }
        }

    }
    static boolean isPalindrome(String s) {
        int n = s.length();
        for (int i = 0; i < (n / 2) + 1; ++i) {
            if (s.charAt(i) != s.charAt(n - i - 1)) {
                return false;
            }
        }

        return true;
    }
}

class Reader {

    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /**
     * call this method to initialize reader for InputStream
     */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    /**
     * get next word
     */
    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

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

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

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

}


import java.util.*;
public class codetest {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int[] correct = new int[input.nextInt()];
        int[] incorrect = new int[input.nextInt()];

        for (int i = 0; i < correct.length; i++)
            correct[i] = input.nextInt();

        for (int i = 0; i < incorrect.length; i++)
            incorrect[i] = input.nextInt();

        Arrays.sort(correct);
        Arrays.sort(incorrect);

        int answer = 0;
        int target = correct[0] * 2;

        if (target > incorrect[0])
            answer = -1;
        else if (correct[correct.length-1] >= target)
            answer = correct[correct.length-1];
        else if (target < incorrect[0])
            answer = target;
        else
            answer = -1;
        System.out.println(answer);
    }

}


import java.util.*;
public class codetest {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int[] correct = new int[input.nextInt()];
        int[] incorrect = new int[input.nextInt()];

        for (int i = 0; i < correct.length; i++)
            correct[i] = input.nextInt();

        for (int i = 0; i < incorrect.length; i++)
            incorrect[i] = input.nextInt();

        Arrays.sort(correct);
        Arrays.sort(incorrect);

        int answer = 0;
        int target = correct[0] * 2;

        if (target >= incorrect[0] || correct[correct.length-1] >= incorrect[0])
            answer = -1;
        else if (correct[correct.length-1] >= target)
            answer = correct[correct.length-1];
        else if (target < incorrect[0])
            answer = target;
        else
            answer = -1;
        System.out.println(answer);
    }

}


import java.util.*;
public class codetest {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int[] correct = new int[input.nextInt()];
        int[] incorrect = new int[input.nextInt()];

        for (int i = 0; i < correct.length; i++)
            correct[i] = input.nextInt();

        for (int i = 0; i < incorrect.length; i++)
            incorrect[i] = input.nextInt();

        Arrays.sort(correct);
        Arrays.sort(incorrect);

        int answer = 0;
        int target = correct[0] * 2;

        if (target > incorrect[0])
            answer = -1;
        else if (correct[correct.length-1] >= target)
            answer = correct[correct.length-1];
        else if (target < incorrect[0])
            answer = target;
        System.out.println(answer);
    }

}


import java.util.*;
public class codetest {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int[] correct = new int[input.nextInt()];
        int[] incorrect = new int[input.nextInt()];

        for (int i = 0; i < correct.length; i++)
            correct[i] = input.nextInt();

        for (int i = 0; i < incorrect.length; i++)
            incorrect[i] = input.nextInt();

        Arrays.sort(correct);
        Arrays.sort(incorrect);

        int answer = 0;
        int target = correct[0] * 2;

        if (correct[correct.length-1] >= target)
            answer = correct[correct.length-1];
        else if (target < incorrect[0])
            answer = target;
        else
            answer = -1;

        System.out.println(answer);
    }

}


import java.util.*;
public class codetest {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int[] correct = new int[input.nextInt()];
        int[] incorrect = new int[input.nextInt()];

        for (int i = 0; i < correct.length; i++)
            correct[i] = input.nextInt();

        for (int i = 0; i < incorrect.length; i++)
            incorrect[i] = input.nextInt();

        Arrays.sort(correct);
        Arrays.sort(incorrect);

        int answer = 0;
        int target = correct[0] * 2;

        if (target >= incorrect[0])
            answer = -1;
        else if (correct[correct.length-1] >= target)
            answer = correct[correct.length-1];
        else if (target < incorrect[0])
            answer = target;
        else
            answer = -1;
        System.out.println(answer);
    }

}


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

public class Main {

	BufferedReader in;
	StringTokenizer str = null;
	PrintWriter out;

	private String next() throws Exception {
		if (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return str.nextToken();
	}

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

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

	public void run() throws Exception {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		int n = nextInt(), m = nextInt();
		int []a = new int[n];
		for(int i = 0; i < n; ++i) a[i] = nextInt();
		int []b = new int[m];
		for(int i = 0; i < m; ++i) b[i] = nextInt();

		for(int t = 1; t <= 1000; ++t) {
			boolean valid = true;
			boolean carry = false;
			for(int i = 0; i < n; ++i) {
				if (a[i] > t) {
					valid = false;
					break;
				}
				if (2 * a[i] <= t) {
					carry = true;
				}
			}
			if (!carry) continue;
			for(int i = 0; i < m; ++i) {
				if (b[i] <= t) {
					valid = false;
					break;
				}
			}
			if (!valid) continue;
			out.println(t);
			out.close();
			return;
		}

		out.println(-1);
		out.close();
	}

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


import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
         //v = min(ai), p = max(ai), c = min(bi). So, if max(2 * v, p) < c, then answer is max(2 * v, p), else answer is  - 1.
        int n = sc.nextInt();
        int m =sc.nextInt();
        int[] array = new int[n];
        int[] array2 = new int[m];

        for(int i = 0 ;  i < n ; ++i)array[i]=sc.nextInt();

        for(int i = 0 ; i < m ; ++i)array2[i]=sc.nextInt();

        Arrays.sort(array);
        int v =array[0];
        int p = array[n-1];

        Arrays.sort(array2);
        int c = array2[0];
        if(Math.max(2*v, p)<c)System.out.println(Math.max(2*v, p));
        else
            System.out.println(-1);
    }

}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m =sc.nextInt();
        int[] array = new int[n];
        int[] array2 = new int[m];
        int max1=0;
        for(int i = 0 ;  i < n ; ++i)
        {
            array[i]=sc.nextInt();
            max1 = Math.max(max1, array[i]);
        }
        for(int i = 0 ; i < m ; ++i)array2[i]=sc.nextInt();
        int mul = 2*max1;
        if(check(array2,mul))System.out.println(max1);
        else
            System.out.println(-1);
    }
  public static boolean check (int[] array,int max)
  {
      for(int i = 0 ; i < array.length;++i)
      {
          if(max<=array[i])return true;
      }
      return false;
  }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m =sc.nextInt();
        int[] array = new int[n];
        int[] array2 = new int[m];
        int max1=0;
        for(int i = 0 ;  i < n ; ++i)
        {
            array[i]=sc.nextInt();
            max1 = Math.max(max1, array[i]);
        }
        for(int i = 0 ; i < m ; ++i)array2[i]=sc.nextInt();
        int mul = 2*max1;
        Arrays.sort(array);
        boolean f= false;
        int count =0;
        for(int i = 0 ; i < n-1;++i)
        {
            if(array[i]<max1)f=true;
            if(2*array[i]<=max1)
            {
                count =1;
            }
            else
            {
                if(count>=1)f=true;
                else
                {
                    f=false;
                    break;
                }
            }
        }
        if(f && count >=1)
        {
            f=false;
            for(int i = 0 ; i < m;++i)
            {
                if(array2[i]>max1)f=true;
                else
                {
                    f=false;
                    break;
                }
            }

        }
        if(f)System.out.println(max1);
        else
            System.out.println(-1);

    }

}


import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m =sc.nextInt();
        int[] array = new int[n];
        int[] array2 = new int[m];
        int max1=0;
        for(int i = 0 ;  i < n ; ++i)
        {
            array[i]=sc.nextInt();
            max1 = Math.max(max1, array[i]);
        }
        for(int i = 0 ; i < m ; ++i)array2[i]=sc.nextInt();
        int mul = 2*max1;
        if(check(array2,mul))System.out.println(max1);
        else
            System.out.println(-1);
    }
  public static boolean check (int[] array,int max)
  {
      for(int i = 0 ; i < array.length;++i)
      {
          if(array[i]==max)return true;
      }
      return false;
  }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m =sc.nextInt();
        int[] array = new int[n];
        int[] array2 = new int[m];
        int max1=0;
        for(int i = 0 ;  i < n ; ++i)
        {
            array[i]=sc.nextInt();
            max1 = Math.max(max1, array[i]);
        }
        for(int i = 0 ; i < m ; ++i)array2[i]=sc.nextInt();
        int mul = 2*max1;
        Arrays.sort(array);
        boolean f= false;
        int count =0;
        for(int i = 0 ; i < n-1;++i)
        {
            if(array[i]<max1)f=true;
            if(2*array[i]<=max1)
            {
                count =1;
            }
            else
            {
                if(count>=1)f=true;
                else
                {
                    f=false;
                    break;
                }
            }
        }
        if(f && count >=1)
        {
            f=false;
            for(int i = 0 ; i < m;++i)
            {
                if(array2[i]>max1)f=true;
                else
                {
                    f=false;
                    break;
                }
            }

        }
        if(f)System.out.println(max1);
        else
        {
            if(n==1)System.out.println(mul);
            else
            System.out.println(-1);
        }
    }
  public static boolean check (int[] array,int max)
  {
      boolean f= false;
      for(int i = 0 ; i < array.length;++i)
      {
          if(max <= array[i])f= true;
          else
          {
              f=false;
              break;
          }
      }
      if(f)return true;

      return false;
  }

}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m =sc.nextInt();
        int[] array = new int[n];
        int[] array2 = new int[m];
        int max1=0;
        for(int i = 0 ;  i < n ; ++i)
        {
            array[i]=sc.nextInt();
            max1 = Math.max(max1, array[i]);
        }
        for(int i = 0 ; i < m ; ++i)array2[i]=sc.nextInt();
        int mul = 2*max1;
        if(check(array2,mul))System.out.println(max1);
        else
            System.out.println(-1);
    }
  public static boolean check (int[] array,int max)
  {
      for(int i = 0 ; i < array.length;++i)
      {
          if(array[i]<=max)return true;
      }
      return false;
  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class P1
{
	public static void main(String[]args) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		int minN = Integer.MAX_VALUE;
		int maxN = Integer.MIN_VALUE;
		st = new StringTokenizer(br.readLine());
		for(int i=0;i<n;i++)
		{
			int a = Integer.parseInt(st.nextToken());
			minN = Math.min(minN, a);
			maxN = Math.max(maxN, a);
		}
		int minM = Integer.MAX_VALUE;
		st = new StringTokenizer(br.readLine());
		for(int i=0;i<m;i++)
		{
			int a = Integer.parseInt(st.nextToken());
			minM = Math.min(minM, a);
		}
		if(minM>maxN&&minM>2*minN)
			System.out.println(maxN);
		else
			System.out.println(-1);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class P1
{
    public static void main(String[]args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int minN = Integer.MAX_VALUE;
        int maxN = Integer.MIN_VALUE;
        st = new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++)
        {
            int a = Integer.parseInt(st.nextToken());
            minN = Math.min(minN, a);
            maxN = Math.max(maxN, a);
        }
        int minM = Integer.MAX_VALUE;
        st = new StringTokenizer(br.readLine());
        for(int i=0;i<m;i++)
        {
            int a = Integer.parseInt(st.nextToken());
            minM = Math.min(minM, a);
        }

        if(minM>maxN&&minM>2*minN&&maxN>=2*minN)
        {
            for(int i=maxN;i<maxN*2;i++)
            {
                if(i==2*minN)
                    System.out.println(i);
            }

        }
        else
            System.out.println(-1);
    }
}


import java.util.*;
import java.io.*;
public class TL
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int minN = Integer.MAX_VALUE;
        int maxN = Integer.MIN_VALUE;
        int minM = Integer.MAX_VALUE;
        st = new StringTokenizer(br.readLine());
        for(int i = 0;i<n;i++)
        {
            int a = Integer.parseInt(st.nextToken());
            maxN = Math.max(maxN, a);
            minN = Math.min(minN, a);
        }
        st = new StringTokenizer(br.readLine());
        for(int i = 0;i<m;i++)
        {
            int a = Integer.parseInt(st.nextToken());
            minM = Math.min(minM, a);
        }
        if(2*minN<minM&&minM>maxN)
        {
            if(2*minN>maxN)
            out.println(2*minN);
            else
            out.println(maxN);
        }
        else
            out.println(-1);
        out.flush();
    }

}


import java.util.*;
import java.io.*;
public class TL
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int minN = Integer.MAX_VALUE;
        int maxN = Integer.MIN_VALUE;
        int minM = Integer.MAX_VALUE;
        st = new StringTokenizer(br.readLine());
        for(int i = 0;i<n;i++)
        {
            int a = Integer.parseInt(st.nextToken());
            maxN = Math.max(maxN, a);
            minN = Math.min(minN, a);
        }
        st = new StringTokenizer(br.readLine());
        for(int i = 0;i<n;i++)
        {
            int a = Integer.parseInt(st.nextToken());
            minM = Math.max(minM, a);
        }
        if(2*minN<minM&&minM>maxN)
        {
            if(2*minN>maxN)
            out.println(2*minN);
            else
            out.println(maxN);
        }
        else
            out.println(-1);
        out.flush();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class P1
{
    public static void main(String[]args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int minN = Integer.MAX_VALUE;
        int maxN = Integer.MIN_VALUE;
        st = new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++)
        {
            int a = Integer.parseInt(st.nextToken());
            minN = Math.min(minN, a);
            maxN = Math.max(maxN, a);
        }
        int minM = Integer.MAX_VALUE;
        st = new StringTokenizer(br.readLine());
        for(int i=0;i<m;i++)
        {
            int a = Integer.parseInt(st.nextToken());
            minM = Math.min(minM, a);
        }
        if(minM>maxN&&minM>2*minN&&maxN>=2*minN)
            System.out.println(maxN);
        else
            System.out.println(-1);
    }
}


import java.util.*;
import java.io.*;
public class TL
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int minN = Integer.MAX_VALUE;
        int maxN = Integer.MIN_VALUE;
        int minM = Integer.MAX_VALUE;
        st = new StringTokenizer(br.readLine());
        for(int i = 0;i<n;i++)
        {
            int a = Integer.parseInt(st.nextToken());
            maxN = Math.max(maxN, a);
            minN = Math.min(minN, a);
        }
        st = new StringTokenizer(br.readLine());
        for(int i = 0;i<m;i++)
        {
            int a = Integer.parseInt(st.nextToken());
            minM = Math.max(minM, a);
        }
        if(2*minN<minM&&minM>maxN)
        {
            if(2*minN>maxN)
            out.println(2*minN);
            else
            out.println(maxN);
        }
        else
            out.println(-1);
        out.flush();
    }

}


import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigInteger;

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

class TaskA {
    public void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        int maxAccepted = -1;
        int minAccepted = 123;
        for(int i = 0; i < n; i++) {
            int times = in.nextInt();
            maxAccepted = Math.max(maxAccepted, times);
            minAccepted = Math.min(minAccepted, times);
        }
        int minWrong = 123;
        for(int i = 0; i < m; i++) {
            int times = in.nextInt();
            minWrong = Math.min(minWrong, times);
        }
        if(maxAccepted > minWrong || minWrong < minAccepted * 2) {
            out.println(-1);
        } else {
            out.println(2 * minAccepted);
        }
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        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.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigInteger;

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

class TaskA {
    public void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        int maxAccepted = -1;
        int minAccepted = 123;
        for(int i = 0; i < n; i++) {
            int times = in.nextInt();
            maxAccepted = Math.max(maxAccepted, times);
            minAccepted = Math.min(minAccepted, times);
        }
        int minWrong = 123;
        for(int i = 0; i < m; i++) {
            int times = in.nextInt();
            minWrong = Math.min(minWrong, times);
        }
        if(maxAccepted >= minWrong || minWrong <= minAccepted * 2) {
            out.println(-1);
        } else {
            out.println(Math.max(maxAccepted, 2 * minAccepted));
        }
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        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.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigInteger;

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

class TaskA {
    public void solve(InputReader in, PrintWriter out) {
    	int n = in.nextInt();
    	int m = in.nextInt();
    	int maxAccepted = -1;
    	int minAccepted = 123;
    	for(int i = 0; i < n; i++) {
    		int times = in.nextInt();
    		maxAccepted = Math.max(maxAccepted, times);
    		minAccepted = Math.min(minAccepted, times);
    	}
    	int minWrong = 123;
    	for(int i = 0; i < m; i++) {
    		int times = in.nextInt();
    		minWrong = Math.min(minWrong, times);
    	}
    	if(maxAccepted >= minWrong || minWrong < minAccepted * 2) {
    		out.println(-1);
    	} else {
    		out.println(Math.max(maxAccepted, 2 * minAccepted));
    	}
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        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.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigInteger;

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

class TaskA {
    public void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        int maxAccepted = -1;
        int minAccepted = 123;
        for(int i = 0; i < n; i++) {
            int times = in.nextInt();
            maxAccepted = Math.max(maxAccepted, times);
            minAccepted = Math.min(minAccepted, times);
        }
        int minWrong = 123;
        for(int i = 0; i < m; i++) {
            int times = in.nextInt();
            minWrong = Math.min(minWrong, times);
        }
        if(maxAccepted > minWrong || minWrong < minAccepted * 2) {
            out.println(-1);
        } else {
            out.println(Math.max(maxAccepted, 2 * minAccepted));
        }
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        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.net.*;
import static java.util.Arrays.*;
import java.util.*;
import java.util.Map.Entry;
public class JavaApplication3
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        ArrayList<Integer> a = new ArrayList<>();
        ArrayList<Integer> b = new ArrayList<>();
        for(int i = 0; i < n; i++)
            a.add(in.nextInt());
        for(int i = 0; i < m; i++)
            b.add(in.nextInt());
        a.sort(null);
        b.sort(null);
        if(a.get(n - 1) >= b.get(0))
        {
            System.out.println("-1");
            return;
        }
        if(2 * a.get(0) < b.get(0) && a.get(n-1) < b.get(0))
            System.out.println(Math.max(2 * a.get(0), a.get(n-1)));
        else
            System.out.println("-1");
    }
}


import java.io.*;
import java.net.*;
import static java.util.Arrays.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.Arrays;
public class JavaApplication3
{
    public static void main(String[] args)
    {
        int q = -1;
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        for(int i = 0; i < n; i++)
            a[i] = (in.nextInt());
        for(int i = 0; i < m; i++)
            b[i] = (in.nextInt());
        Arrays.sort(a);
        Arrays.sort(b);
        if(a[n - 1] >= b[0])
        {
            System.out.println("-1");
            return;
        }
        if(2 * a[0] < b[0] && a[n-1] < b[0])
            System.out.println(Math.max(2 * a[0], a[n-1]));
        else
            System.out.println(q);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;

public class Main5 {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line = "";
        StringBuilder out = new StringBuilder();
        while ((line = in.readLine()) != null && line.length() != 0) {
            int[] c = retInts(in.readLine());
            int[] w = retInts(in.readLine());
            Arrays.sort(c);
            Arrays.sort(w);
            int minW = w[0];
            if (w[0] < c[c.length - 1])
                out.append("-1\n");
            else {
                boolean almostOne = false;
                int ans = -1;
                for (int i = c[c.length - 1]; i < w[0]; i++) {
                    almostOne = false;
                    for (int j = 0; j < c.length - 1; j++)
                        if (c[j] * 2 <= i) {
                            almostOne = true;
                            break;
                        }
                    if (almostOne) {
                        ans = i;
                        break;
                    }
                }
                out.append(ans + "\n");
            }
        }
        System.out.print(out);
    }

    public static int[] retInts(String line) {
        String[] w = line.split(" ");
        int[] nums = new int[w.length];
        for (int i = 0; i < w.length; i++)
            nums[i] = Integer.parseInt(w[i]);
        return nums;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;

public class Main5 {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line = "";
        StringBuilder out = new StringBuilder();
        while ((line = in.readLine()) != null && line.length() != 0) {
            int[] c = retInts(in.readLine());
            int[] w = retInts(in.readLine());
            Arrays.sort(c);
            Arrays.sort(w);
            int minW = w[0];
            if (w[0] < c[c.length - 1])
                out.append("-1\n");
            else {
                boolean almostOne = false;
                int ans = -1;
                for (int i = c[c.length - 1]; i < w[0]; i++) {
                    almostOne = false;
                    for (int j = 0; j < c.length; j++)
                        if (c[j] * 2 <= i) {
                            almostOne = true;
                            break;
                        }
                    if (almostOne) {
                        ans = i;
                        break;
                    }
                }
                out.append(ans + "\n");
            }
        }
        System.out.print(out);
    }

    public static int[] retInts(String line) {
        String[] w = line.split(" ");
        int[] nums = new int[w.length];
        for (int i = 0; i < w.length; i++)
            nums[i] = Integer.parseInt(w[i]);
        return nums;
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class AA {

	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[]correct=new int[n];
		int[]wrong=new int[m];
		for(int i=0;i<n;i++)
			correct[i]=sc.nextInt();

		for(int i=0;i<m;i++)
			wrong[i]=sc.nextInt();

		Arrays.sort(correct);
		Arrays.sort(wrong);
		int numm=correct[n-1];

		if(numm==correct[0]||numm>wrong[0]){
			System.out.println(-1);
			return;
		}
		else{
			while(numm<wrong[0]){
			if(correct[0]*2>numm)
			numm++;
			else break;
			}
		}
	//	System.out.println(numm);
		if(correct[0]*2<=numm)
			System.out.println(numm);
		else System.out.println(-1);

	}

}


import java.util.Arrays;
import java.util.Scanner;

public class AA {

	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[]correct=new int[n];
		int[]wrong=new int[m];
		for(int i=0;i<n;i++)
			correct[i]=sc.nextInt();

		for(int i=0;i<m;i++)
			wrong[i]=sc.nextInt();

		Arrays.sort(correct);
		Arrays.sort(wrong);
		int numm=correct[n-1];
		if(numm==correct[0]||numm>wrong[0]){
			System.out.println(-1);
			return;
		}
		else if(correct[0]*2>numm){
			System.out.println(-1);
			return;
		}
		else
			System.out.println(numm);

	}

}


import java.util.Arrays;
import java.util.Scanner;

public class Tl {

	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[]correct=new int[n];
		int[]wrong=new int[m];
		for(int i=0;i<n;i++)
			correct[i]=sc.nextInt();
		for(int i=0;i<m;i++)
			wrong[i]=sc.nextInt();
		Arrays.sort(correct);
		int max=correct[correct.length-1];
		int min=correct[0];
		Arrays.sort(wrong);
		int minfalse=wrong[0];
		for(int i=max;i<=minfalse-1;i++){
			if(min*2<i)
			{
				System.out.println(i);
				return;
			}

		}
		System.out.println(-1);

	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Tl {

	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[]correct=new int[n];
		int[]wrong=new int[m];
		for(int i=0;i<n;i++)
			correct[i]=sc.nextInt();
		for(int i=0;i<m;i++)
			wrong[i]=sc.nextInt();
		Arrays.sort(correct);
		int max=correct[correct.length-1];
		int min=correct[0];
		Arrays.sort(wrong);
		int minfalse=wrong[0];
		for(int i=max;i<=minfalse-1;i++){
			if(min*2<=i)
			{
				System.out.println(i);
				return;
			}

		}
		System.out.println(-1);

	}
}


import java.util.Arrays;
import java.util.Scanner;

public class AA {

	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[]correct=new int[n];
		int[]wrong=new int[m];
		for(int i=0;i<n;i++)
			correct[i]=sc.nextInt();

		for(int i=0;i<m;i++)
			wrong[i]=sc.nextInt();

		Arrays.sort(correct);
		Arrays.sort(wrong);
		int num=correct[n-1];
		if(num==correct[0]||num>wrong[0]){
			System.out.println(-1);
			return;
		}
		else if(correct[0]*2>num){
			System.out.println(-1);
			return;
		}
		else
			System.out.println(num);

	}

}


import java.util.Arrays;
import java.util.Scanner;

public class AA {

	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[]correct=new int[n];
		int[]wrong=new int[m];
		for(int i=0;i<n;i++)
			correct[i]=sc.nextInt();

		for(int i=0;i<m;i++)
			wrong[i]=sc.nextInt();

		Arrays.sort(correct);
		Arrays.sort(wrong);
		int numm=correct[n-1];

		if(numm==correct[0]||numm>wrong[0]){
			System.out.println(-1);
			return;
		}
		else{
			while(numm+1!=wrong[0]){
			if(correct[0]*2>numm)
			numm++;
			else break;
			}
		}
	//	System.out.println(numm);
		if(correct[0]*2<=numm)
			System.out.println(numm);
		else System.out.println(-1);

	}

}


import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class prob {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a[] = new int[n + 1];
		int b[] = new int[m + 1];
		for (int i = 1; i <= n; i++)
			a[i] = sc.nextInt();
		for (int i = 1; i <= m; i++)
			b[i] = sc.nextInt();
		Arrays.sort(a, 1, n + 1);
		int min = a[1];
		int max = a[n];
		for (int i = 1; i <= n; i++) {
			if (min > a[i])
				min = a[i];
			if (max < a[i])
				max = a[i];
		}
		int ans = 0;
		Arrays.sort(b, 1, m + 1);
		if (min * 2 > max)
			ans = 2 * min;
		if (ans < b[1])
			ans = b[1] - 1;
		else
			ans = -1;
		System.out.println(ans);
	}
}


import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class prob {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a[] = new int[n + 1];
		int b[] = new int[m + 1];
		for (int i = 1; i <= n; i++)
			a[i] = sc.nextInt();
		for (int i = 1; i <= m; i++)
			b[i] = sc.nextInt();
		Arrays.sort(a, 1, n + 1);
		Arrays.sort(b, 1, m + 1);
		int ans = Math.max(2*a[1], a[n]);
		if (ans < b[1])
			System.out.println(ans);
		else
			System.out.println(-1);
	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 *
 * @author Jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
        String S[] = br.readLine().split(" ");
        int N = Integer.parseInt(S[0]);
        int M = Integer.parseInt(S[1]);
        S = br.readLine().split(" ");
        int correct[] = new int[N];
        int incorrect[] = new int[M];
        for(int n=0;n<N;n++){
            correct[n] = Integer.parseInt(S[n]);
        }
        S = br.readLine().split(" ");
        for(int n=0;n<M;n++){
            incorrect[n] = Integer.parseInt(S[n]);
        }
        Arrays.sort(correct);
        Arrays.sort(incorrect);
        if(correct[N-1]>=incorrect[0]){
            pw.println("-1");
        }
        else if(correct[0]>correct[N-1]/2){
            pw.println("-1");
        }
        else{
            pw.println(correct[N-1]);
        }
        pw.close();
    }

}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 *
 * @author Jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
        String S[] = br.readLine().split(" ");
        int N = Integer.parseInt(S[0]);
        int M = Integer.parseInt(S[1]);
        S = br.readLine().split(" ");
        int correct[] = new int[N];
        int incorrect[] = new int[M];
        for(int n=0;n<N;n++){
            correct[n] = Integer.parseInt(S[n]);
        }
        S = br.readLine().split(" ");
        for(int n=0;n<M;n++){
            incorrect[n] = Integer.parseInt(S[n]);
        }

        Arrays.sort(correct);
        Arrays.sort(incorrect);
        if(N==1){
            if((2*correct[0])<incorrect[0]){
                pw.println(2*correct[0]);
            }
            else{
                pw.println("-1");
            }
        }

        else if(correct[N-1] >= incorrect[0])
        {
            pw.println("-1");
        }
        else if(correct[0]<(correct[N-1]/2)){
            pw.println(correct[N-1]);
        }
        else if((2*correct[0])<incorrect[0]){
            pw.println(2*correct[0]);
        }
        else{
            pw.println("-1");
        }
        pw.close();
    }

}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 *
 * @author Jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
        String S[] = br.readLine().split(" ");
        int N = Integer.parseInt(S[0]);
        int M = Integer.parseInt(S[1]);
        S = br.readLine().split(" ");
        int correct[] = new int[N];
        int incorrect[] = new int[M];
        for(int n=0;n<N;n++){
            correct[n] = Integer.parseInt(S[n]);
        }
        S = br.readLine().split(" ");
        for(int n=0;n<M;n++){
            incorrect[n] = Integer.parseInt(S[n]);
        }

        Arrays.sort(correct);
        Arrays.sort(incorrect);
        if(N==1){
            if((2*correct[0])<incorrect[0]){
                pw.println(2*correct[0]);
            }
            else{
                pw.println("-1");
            }
        }

        else if(correct[N-1] >= incorrect[0])
        {
            pw.println("-1");
        }
        else if(correct[0]<=(correct[N-1]/2)){
            pw.println(correct[N-1]);
        }
        else if((2*correct[0])<incorrect[0]){
            pw.println(2*correct[0]);
        }
        else{
            pw.println("-1");
        }
        pw.close();
    }

}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 *
 * @author Jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
        String S[] = br.readLine().split(" ");
        int N = Integer.parseInt(S[0]);
        int M = Integer.parseInt(S[1]);
        S = br.readLine().split(" ");
        int correct[] = new int[N];
        int incorrect[] = new int[M];
        for(int n=0;n<N;n++){
            correct[n] = Integer.parseInt(S[n]);
        }
        S = br.readLine().split(" ");
        for(int n=0;n<M;n++){
            incorrect[n] = Integer.parseInt(S[n]);
        }

        Arrays.sort(correct);
        Arrays.sort(incorrect);
        if(N==1){
            if((2*correct[0])<incorrect[0]){
                pw.println(2*correct[0]);
            }
            else{
                pw.println("-1");
            }
        }

        else if(correct[N - 1] >= incorrect[0])
        {
            pw.println("-1");
        }
        else if(correct[0]>correct[N-1]/2){
            pw.println("-1");
        }
        else{
            pw.println(correct[N-1]);
        }
        pw.close();
    }

}


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

public class Main{

    public static void main(String []args) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> Arr = new ArrayList<>();

    StringTokenizer input = new StringTokenizer(in.readLine());

    int A = Integer.parseInt(input.nextToken()),B = Integer.parseInt(input.nextToken()),count = 0,v1, v;

boolean  check[]=new boolean[2];
check[1]=true;
   input = new StringTokenizer(in.readLine());
   int arr1[] = new int [A];
   while(input.hasMoreTokens())
   {
       arr1[count]=Integer.parseInt(input.nextToken());
       count++;

   }
   count = 0 ;
   input = new StringTokenizer(in.readLine());
   int arr2[];
        arr2 = new int [B];
   while(input.hasMoreTokens())
   {
       arr2[count]=Integer.parseInt(input.nextToken());
       count++;

   }
  Arrays.sort(arr2);v=arr2[0]-1;
  Arrays.sort(arr1);v1=arr1[arr1.length-1];
  while(v>=v1)
  {
  for (int i = 0 ; i < arr1.length;i++)
  {
      if(arr1[i]*2<=v)check[0]=true;
      if(!(arr1[i]<=v))check[1]=false;

  }
  if(check[0] && check[1])
      Arr.add(v);
  check[1]=true;
  check[0]=false;
  v--;}
  Collections.sort(Arr);
  if(Arr.size()>0)System.out.println(Arr.get(0));
  else
            System.out.println(-1);

    }

    }


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

public class TL {

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

class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		int n = in.nextInt(), m = in.nextInt();
		int[] a = new int[n];
		int[] b = new int[m];
		int i, j, k;
		int v = -1;

		for (i=0; i<n; ++i)
			a[i] = in.nextInt();
		for (i=0; i<m; ++i)
			b[i] = in.nextInt();
		Arrays.sort(a);
		Arrays.sort(b);

		v = Math.max(a[0]+a[0], a[n-1]);

		if (v >= b[0])
			v = -1;
		out.println(v);
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

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

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

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

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


import java.util.*;
import java.io.*;
public class Task203A {

	Scanner sc;
	BufferedReader buf;
	PrintWriter pw;
	Task203A() {
		buf = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
		try {
			go();
		} catch (Exception ex) {ex.printStackTrace();}
	}
	StringTokenizer st = new StringTokenizer("");
	public String nextToken() throws IOException{
		while(!st.hasMoreElements()) {
			st = new StringTokenizer(buf.readLine());
		}
		return st.nextToken();
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}
	public void go() throws IOException{
		int n = nextInt();
		int m = nextInt();
		int[] accept = new int[n];
		int[] wa = new int[m];
		for (int i = 0; i < n; i++) {
			accept[i] = nextInt();
		}
		for (int i = 0; i < m; i++) {
			wa[i] = nextInt();
		}
		Arrays.sort(accept);
		Arrays.sort(wa);
		boolean isTrue = true;
		int el = accept[0];
		if (accept.length > 1 && el*2 <= accept[accept.length-1]) {
			el = accept[accept.length-1];
			for (int i = 0; i < m; i++) {
				if (el >= wa[i]) {
					isTrue = false;
					break;
				}
			}
		} else if (accept.length == 1 || el <= accept[accept.length-1]) {
			el *= 2;
			for (int i = 0; i < m; i++) {
				if (el >= wa[i]) {
					isTrue = false;
					break;
				}
			}
		} else
			isTrue = false;
		System.out.println(isTrue?el:-1);
	}
	public static void main(String[] args) {
		new Task203A();
	}

}


import java.util.*;
import java.io.*;
public class Task203A {

	Scanner sc;
	BufferedReader buf;
	PrintWriter pw;
	Task203A() {
		buf = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
		try {
			go();
		} catch (Exception ex) {ex.printStackTrace();}
	}
	StringTokenizer st = new StringTokenizer("");
	public String nextToken() throws IOException{
		while(!st.hasMoreElements()) {
			st = new StringTokenizer(buf.readLine());
		}
		return st.nextToken();
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}
	public void go() throws IOException{
		int n = nextInt();
		int m = nextInt();
		int[] accept = new int[n];
		int[] wa = new int[m];
		for (int i = 0; i < n; i++) {
			accept[i] = nextInt();
		}
		for (int i = 0; i < m; i++) {
			wa[i] = nextInt();
		}
		Arrays.sort(accept);
		Arrays.sort(wa);
		boolean isTrue = true;
		int el = accept[accept.length-1];
		if (accept.length > 1 && el >= accept[0]*2) {
			for (int i = 0; i < m; i++) {
				if (el >= wa[i]) {
					isTrue = false;
					break;
				}
			}
		} else if (accept.length == 1 || el == accept[0]) {
			el *= 2;
			for (int i = 0; i < m; i++) {
				if (el >= wa[i]) {
					isTrue = false;
					break;
				}
			}
		} else
			isTrue = false;
		System.out.println(isTrue?el:-1);
	}
	public static void main(String[] args) {
		new Task203A();
	}

}