'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const NM = inp.shift().split(' ').map(n => Number(n))
  inp = inp.map(r => r.split(' ').map(n => Number(n)))
    .sort((a, b) => a[0] - b[0])
  
  const work = (inp, day, remove) => {
    let moneybag = []
    let arr = JSON.parse(JSON.stringify(inp))
    if (remove !== null) arr.splice(remove, 1)
    for (let i = 0; i < arr.length; i++) {
      if (arr[i][0] + day - 1 <= NM[1]) {
        moneybag.push(arr[i][1] + work(arr, day+1, i))
      } else {
        break;
      }
    }
    return moneybag.length ? Math.max(...moneybag) : 0
  }
  console.log(work(inp, 1, null))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
