import std.stdio;
import std.exception;
import std.conv;
import std.container;
import std.algorithm;
import std.functional;
import std.range;
import std.array;

const bool DEBUG = false;

const ulong C = 1000000007;
ulong[100001] fact;
static this() {
    fact[0] = 0;
    fact[1] = 1;
    foreach (i; 2 .. 100001) {
        fact[i] = fact[i - 1] * i % C;
    }
}

void main() {
    int N, R;
    while (readf("%d\n", &N), N) {
        readf("%d\n", &R);
        int[] str = new int[N];
        foreach (int i, ref c; str) c = i;
        bool[] flag = new bool[N];
        foreach (i; 0 .. R) {
            int s, t; readf("%d %d\n", &s, &t);
            s--; t--;
            flag[s] = flag[t] = true;
            swap(str[s], str[t]);
        }
        ulong ans = 0;
        int c = 0;
        int[] diff = new int[N];
        foreach (i; 0 .. N) {
            if (flag[i]) diff[str[i]]++;
            c += diff[i];
            ans = (ans + max(0, (str[i] - c)) * fact[N - 1 - i]) % C;
            static if (DEBUG) {
                [str[i], c, N - 1 - i, ans].write;
                diff.writeln;
            }
            if (!flag[i]) c++;
        }
        ans.writeln;
    }
}