class LazySegmentTreeBase
  def initialize(l, r)
    @l, @r = l, r
    @lazy = nil
    if l == r
      @completed = 0
    else
      c = (l + r) / 2
      @left_child = self.class.new(l, c)
      @right_child = self.class.new(c + 1, r)
    end
  end

  attr_reader :l, :r

  def update(l, r, x)
    if l == @l && r == @r
      defer(x)
    else
      force
      if r <= @left_child.r
        @left_child.update(l, r, x)
      elsif @right_child.l <= l
        @right_child.update(l, r, x)
      else
        @left_child.update(l, @left_child.r, x)
        @right_child.update(@right_child.l, r, x)
      end
    end
  end

  def force
    return if !@lazy
    x = @lazy
    @lazy = nil
    whole_update(x) if @l == @r
    @left_child.update(@left_child.l, @left_child.r, x) if @left_child
    @right_child.update(@right_child.l, @right_child.r, x) if @right_child
  end

  def query(i)
    force
    return @completed if @l == @r
    if i <= @left_child.r
      return @left_child.query(i)
    else @right_child.l <= i
      return @right_child.query(i)
    end
  end
end

class LazySegmentTree < LazySegmentTreeBase
  def defer(x)
    if !@lazy
      @lazy = x.dup
    elsif x[0] == @lazy[-1] + 1
      @lazy[1] = x[1]
    else
      @lazy = [-1, -1]
    end
  end

  def whole_update(x)
    if x[0] == @completed + 1
      @completed = x[1]
    else
      @completed = -1
    end
  end
end

n, k = gets.split.map(&:to_i)
seg = LazySegmentTree.new(1, n)
q = gets.to_i
q.times do
  l, r, x = gets.split.map(&:to_i)
  seg.update(l, r, [x, x])
end

answer = 0
(1..n).each do |i|
  c = seg.query(i)
  answer += 1 if c == k
end
p answer
