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 ulong C = 1000000007;
ulong[100001] fact;
static this() {
    fact[0] = 1;
    foreach (i; 1 .. 100001) {
        fact[i] = fact[i - 1] * i % C;
    }
}

class SegmentTree {
    int values[];
    SegmentTree left, right; 
    SegmentTree parent;
    int from, to;
    int diff;
    ~this() {
        delete left;
        delete right;
    }
    this(int[] values, SegmentTree parent = null, int from = 0, int to = -1) {
        //writeln(parent is null);
        if (to == -1) to = cast(int)values.length;
        this.values = values;
        this.parent = parent;
        this.from = from;
        this.to = to;
        this.diff = 0;
        if (from + 1 != to) {
            int mid = (from + to + 1) / 2;
            this.left  = new SegmentTree(values, this, from, mid);
            this.right = new SegmentTree(values, this, mid, to);
        }
    }
    void add(int x, int from, int to) {
        if (from >= to) return;
        if (this.from == from && this.to == to) {
            diff += x;
        } else {
            left.add(x, max(from, left.from), min(to, left.to));
            right.add(x, max(from, right.from), min(to, right.to));
        }
    }
    int opIndex(ulong index) {
        if (from == index && index + 1 == to) return values[from] + diff;
        int mid = (from + to + 1) / 2;
        return (index < mid ? left : right).opIndex(index) + diff;
    }
}

void main() {
    int N, R;
    int tc = 0;
    while (readf("%d\n", &N), N) {
        readf("%d\n", &R);
        int[] str = new int[N];
        foreach (int i, ref c; str) c = i;
        foreach (i; 0 .. R) {
            int s, t; readf("%d %d\n", &s, &t);
            s--; t--;
            swap(str[s], str[t]);
        }
        ulong ans = 0;
        int[] _ = new int[N];
        auto segtree = new SegmentTree(_);
        foreach (i; 0 .. N) {
            ans = (ans + (str[i] - segtree[str[i]]) * fact[N - 1 - i]) % C;
            segtree.add(1, str[i] + 1, N);
        }
        ans.writeln;
        delete segtree;
        delete str;
        delete _;
    }
}