public void solve() throws IOException {
    int n = nextInt();
    int m = nextInt();
    int[] a = new int[n];
    int[] b = new int[m];

    for (int x = 0; x < n; x++)
      a[x] = nextInt();
    for (int x = 0; x < m; x++)
      b[x] = nextInt();

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

    if (a[n - 1] >= b[0]) {
      out.println(-1);
      return;
    }

    if (n == 1) {
      if (a[0] * 2 < b[0]) {
        out.println(a[0] * 2);
      } else
        out.println(-1);
      return;
    }

    if (2 * a[0] >= b[0]) {
      out.println(-1);
      return;
    }

    out.println(Math.max(2 * a[0], a[n - 1]));
  }