#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
const ll MOD = 1000000007LL;
int N;
ll fact[200000];

int bit[200000];
int sum(int i) {
  int s = 0;
  while( i > 0 ){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}
void add(int i,int x) {
  while(i<200000){
    bit[i] += x;
    i += i & -i;
  }
}

ll compute(vector<int> vec){
  ll ret = fact[vec.size()];
  set<int> S;
  rep(i,vec.size()) {
    ll coef = N - ( sum(N) - sum(vec[i]-1) ) - vec[i];
    assert( coef >= 0 );
    ret = ( ret -  ( coef * fact[N-i-1] ) % MOD + MOD ) % MOD;
    S.insert(vec[i]);
    add(vec[i],1);
  }
  return (ret-1LL+MOD)%MOD;
}

int main(){
  fact[0] = fact[1] = 1LL;
  REP(i,2,200000) fact[i] = ( fact[i-1] * ll(i) ) % MOD;
  while( cin >> N, N ){
    rep(i,N+1) bit[i] = 0;
    vector<int> vec(N);
    rep(i,N) vec[i] = i+1;
    int R;
    cin >> R;
    rep(_,R){
      int s,t;
      cin >> s >> t;
      --s, --t;
      swap(vec[s],vec[t]);
    }
    cout << compute(vec) << endl;
  }
  return 0;
}