#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

const long long mod = 1000000007;

class BIT{
public:
    vector<long long> v;
    BIT(int _n) {
	int n = 1;
	while (n < _n) n *= 2;
	v.resize(n, 0);
    }
    void add(int p, long long val) {
	for (int t = p; t > 0; t -= (t & -t)) {
	    v[t] += val;
	}
    }
    long long query(int p) {
	long long ans = 0;
	for (int t = p; t < v.size(); t += (t & -t)) {
	    ans += v[t];
	}
	return ans;
    }
};

int main() {
    int n;
    while (cin >> n, n) {
	vector<int> nlist(n);
	int R;
	cin >> R;
	for (int i = 1; i <= n; i++) {
	    nlist[i - 1] = i;
	}
	while (R--) {
	    int a, b;
	    cin >> a >> b;
	    a--;
	    b--;
	    swap(nlist[a], nlist[b]);
	}
	BIT bit(n + 1);
	vector<long long> fact(n + 1, 1);
	for (int i = 1; i <= n; i++) {
	    fact[i] = (fact[i - 1] * i) % mod;
	}
	
	long long ans = 0;
	for (int i = 0; i < n; i++) {
	    int v = nlist[i] - (i - bit.query(nlist[i]));
	    if (v > 1) {
		ans = (ans + (v - 1) * fact[n - i - 1]) % mod;
	    }
	    bit.add(nlist[i], 1);
	}
	cout << ans << endl;
    }
    return 0;
}

