(N,T),*A = ARGF.map{_1.split.map(&:to_i)}
manzoku = Array.new(6000,0)
A.compact.sort.map{|time, value|
  T.downto(1){|turn|
    end_turn = turn + time
    manzoku[end_turn] = [manzoku[end_turn], manzoku[turn] + value].max
    }
  }
puts manzoku.max