#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,R,c[100010];
ll fact[100010];

//
const int M=1<<17;
ll bit[M+1];
 
ll sum(int i){
	ll s=0;
	while(i){
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}
 
void add(int i,ll x){
	while(i<=M){
		bit[i]+=x;
		i+=i&-i;
	}
}
//

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>N>>R && N){
		memset(bit,0,sizeof(bit));
		rep(i,N)c[i]=i+1;
		rep(i,R){
			int s,t;
			cin>>s>>t;
			swap(c[s-1],c[t-1]);
		}
	
		fact[0]=1;
		rep2(i,1,N+1)fact[i]=fact[i-1]*i%MOD;
		ll ans=0;
		rep(i,N){
			ans+=(c[i]-1-sum(c[i]-1)) * fact[N-1-i];
			ans%=MOD;
			add(c[i],1);
		}
		cout<<ans<<endl;
	}
}