### constant

MOD = 1000000007

### 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 = (0...n).to_a
  base = (0...n).to_a

  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

  while ! words.empty?
    k = words.shift
    i = base.index(k)
    base.delete_at(i)

    count = (count + i * facts[words.length]) % MOD
  end

  p count
end