#include <bits/stdc++.h>

using namespace std;

typedef long long Int;

const int INF = 1001001001;

int N, M;
int val[100000];
vector<int> other;

bool ok(int T)
{
    int dp[200000];
    
    fill(dp, dp + 200000, INF);
    
    for (int i = 0; i < N; i++){
        dp[i] = (~val[i] ? (val[i] >= T ? 0 : INF) : 1);
    }
    
    int ct = 0;
    for (int i = 0;; i++){
        dp[i + N] = min(min(dp[i * 3] + dp[i * 3 + 1],
                            dp[i * 3] + dp[i * 3 + 2]),
                        dp[i * 3 + 1] + dp[i * 3 + 2]);
        dp[i + N] = min(dp[i + N], INF);
        ct = dp[i + N];
        if (i * 3 + 3 == i + N) break;
    }
    
    int ct2 = 0;
    
    for (int i = 0; i < other.size(); i++){
        ct2 += other[i] >= T;
    }
    
    return (ct <= ct2);
}

int main()
{
    scanf("%d %d", &N, &M);
    
    memset(val, -1, sizeof(val));
    
    for (int i = 0; i < M; i++){
        int x, y;
        scanf("%d %d", &x, &y);
        val[--y] = x;
    }
    
    for (int i = 0; i < N - M; i++){
        int x;
        scanf("%d", &x);
        other.push_back(x);
    }
    
    int l = 1, r = 1000000000;
    
    while (l != r){
        int mid = (l + r + 1) >> 1;
        
        if (ok(mid)) l = mid;
        else r = mid - 1;
    }
    
    printf("%d\n", l);
    
    return (0);
}