use proconio::input;

fn main () {
    input! {
        n: usize,
        p: u64,
        k: usize,
    }
    let mut s: Vec<(usize,u64)> = Vec::new();
    s.push((1,0));
    for _ in 0..n { 
        input! {
            t: usize,
            b: u64,
        }
        s.push((t, b));
    }
    let p = if p > (1<<18) {0} else {p};
    let mut dp: Vec<Vec<u64>> = vec![vec![p;n+1];n+1];
    for i in 1..dp.len() {
        for j in i..dp[i].len() {
            if dp[i][j-1] == 0 {
                dp[i][j] = dp[i][j-1];
            }
            else {
                dp[i][j] = dp[i][j-1].max(
                    if s[j].0 == 1 { dp[i-1][j-1]+s[j].1 }
                    else {dp[i-1][j-1]*2}
                );
                if dp[i][j] > (1<<18) { dp[i][j] = 0; }
            }
        }
    }
    //println!("{:?}", dp);
    if dp[k][n] == 0 {println!("{}", -1);}
    else {println!("{}", dp[k][n])};
    
}