(N,T),*A = ARGF.map{_1.split.map(&:to_i)}
onaka = Array.new(6001, 0)
A.compact.sort.map{|time, value|
  next if !(time && value)
  T.downto(1){total = _1 + time
    onaka[total] = [onaka[total], (onaka[_1] + value)].max
    }
  }
p onaka.max