#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

int MOD = 1000000007;

int func(int N)
{
    vi w(N);
    iota(w.begin(), w.end(), 0);
    
    int R;
    cin >> R;
    rep(i, R){
        int s, t;
        cin >> s >> t;
        swap(w[s-1], w[t-1]);
    }
    
    ll fact = 1;
    ll ans = 0;
    set<int> S;
    rep(i, N){
        int r = distance(S.begin(), S.lower_bound(w[N-i-1]));
        S.insert(w[N-i-1]);
        ans += fact * r;
        ans %= MOD;
        fact = (fact * (i+1)) % MOD;
    }
    
    return ans;
}

int main()
{
    int N;
    while(cin >> N, N){
        cout << func(N) << endl;
    }
}