use std::cmp;

fn main() {
    let nc: Vec<i64> = read_vec();
    let n = nc[0] as usize;
    let c = nc[1];
    let xvs: Vec<Vec<i64>> = read_vec2(n as u32);
    let mut xvs_r = xvs.clone();
    xvs_r.reverse();
    let xvs_r = xvs_r;


    let mut r1: i64 = 0;
    let mut cals1: Vec<i64> = Vec::new();
    for (ni, i) in xvs.iter().enumerate() {
        let x = i[0];
        let v = i[1];

        tab += v;
        let cal = tab - x;
        if cal > r1 {
            r1 = cal;
        }
        cals1.push(r1);
    }

    let mut r2: i64 = 0;
    let mut cals2: Vec<i64> = Vec::new();
    for (ni, i) in xvs_r.iter().enumerate() {
        let x = c - i[0];
        let v = i[1];

        tab += v;
        let cal = tab - x;
        if cal > r2 {
            r2 = cal;
        }
        cals2.push(r2);
    }
    
    let mut r: i64 = 0;
    for i in 0..n {
        for ir in 0..n {
            if i + ir >= n - 1 {
                break;
            }
            let cal = cals1[i] + cals2[ir] - xvs_r[ir][0];
            if cal > r {
                r = cal;
            }
        }
    }

    println!("{}", r);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_lines<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}