### constant

MOD = 1000000007

### classes

class Bit
  @tree = []
  @size = 0

  def initialize(size)
    @size = size
    @tree = Array.new(size + 1){0}
  end

  def sum(i)
    sum = 0
    while i > 0
      sum += @tree[i]
      i -= (i & -i)
    end
    sum
  end

  def add(i, val)
    while i <= @size
      @tree[i] += val
      i += (i & -i)
    end
  end
end

### main

while true
  $n = gets.strip.to_i
  break if $n == 0

  facts = [1]
  for i in (1..$n)
    facts[i] = (i * facts[i - 1]) % MOD
  end

  words = (1..$n).to_a
  bit = Bit.new($n)

  r = gets.strip.to_i

  r.times do
    si, ti = gets.strip.split(' ').map{|s| s.to_i}
    si -= 1
    ti -= 1
    tmp = words[si]; words[si] = words[ti]; words[ti] = tmp
  end

  count = 0

  for i in (0...$n)
    w = words[$n - 1 - i]
    count = (count + (bit.sum(w - 1) * facts[i]) % MOD) % MOD
    bit.add(w, 1)
  end

  puts count
end