class BIT
    def initialize(n)
        @n = n+1
        @dat = Array.new(@n+1, 0)
    end

    def sum(i)
        s = 0
        while i >= 0 do
            s += @dat[i]
            i = (i & (i + 1)) - 1
        end
        s
    end

    def add(i, x)
        while i <= @n do
            @dat[i] += x
            i |= i + 1
        end
    end
end


N, M = gets.split.map(&:to_i)
#N, M = 3 * 10**5, 10**5

ls, rs = [], []
i = 0
STDIN.each_line do |line|
    ls[i], rs[i] = line.split.map(&:to_i)
    i += 1
    #ls[i], rs[i] = 1, (i%M)+1
end
exit
order = N.times.sort_by{|i|rs[i]-ls[i]}

bit = BIT.new(M+1)

(1..M).each do |m|
    while order.length > 0
        i = order[0]
        if rs[i]-ls[i]+1 < m
            order.shift
            bit.add(ls[i], 1)
            bit.add(rs[i]+1, -1)
        else
            break
        end
    end
    sum = order.length
    (1..(M/m)).each do |k|
        sum += bit.sum(k*m)
    end
    puts sum
end