n,t = gets.split.map(&:to_i)
list = (1..n).map{gets.split.map(&:to_i)}.sort
tm = t-1
dp = [0]*(t)
ans = 0
list.each{|a,b|
  if ans < tmpans=dp[tm]+b
    ans = tmpans
  end
  dp2=[0]*a+dp
  (a..tm).each{|ti|
    if dp[ti] < dpb=dp2[ti]+b
      dp[ti] = dpb
    end
  }
}
p ans