MODV = 1_000_000_007

loop {
  n = gets.to_i
  break if n==0
  r = gets.to_i
  str = (0..n).to_a
  r.times{
    s, t = gets.split.map(&:to_i)
    str[s], str[t] = str[t], str[s]
  }
  res = 0
  fact = 1
  arr = [str[n]]
  (1...n).each{|i|
    fact *= i
    fact %= MODV
    pos = n - i
    chr = str[pos]
    ins_p = arr.bsearch_index{|x| x >= chr}
    ins_p = i unless ins_p
    res += fact * ins_p
    res %= MODV
    arr.insert(ins_p, chr)
  }
  puts res % MODV
}
