#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <climits>
#include <stack>
#include <string>
#include <random>
#include<set>
#include <iomanip>
#include <climits>
#include <memory>

constexpr int mod = 1000000007;
class Sum_Bit {
	std::vector<int> _array;
public:
	explicit Sum_Bit(const int size) :_array(size, 0) {}
	void increment(int index, const int value) {
		while (index < _array.size()) {
			_array[index] += value;
			index += ~index & (index + 1);
		}
	}
	int operator[](int index) const {
		auto result = 0;
		while (index >= 0) {
			result += _array[index];
			index -= ~index & (index + 1);
		}
		return result;
	}
};
int main() {
	std::vector<long long int> factorial(100001, 1);
	for (auto i = 2; i < factorial.size(); ++i) factorial[i] = i * factorial[i - 1] % mod;
	factorial[0] = 0;
	int n; std::cin >> n;
	while (n != 0) {
		int r; std::cin >> r;
		std::vector<int> word(n);
		for (auto i = 0; i < n; ++i) {
			word[i] = i;
		}
		int s, t;
		for (auto i = 0; i < r; ++i) {
			std::cin >> s >> t; --s; --t;
			word[s] -= word[t];
			word[t] += word[s];
			word[s] = word[t] - word[s];
		}
		Sum_Bit bit(n);
		long long int result = 0;
		for (auto i = 0; i < n; ++i) {
			auto num = bit[word[i]];
			result += (word[i] - num) * factorial[n - i - 1];
			result %= mod;
			bit.increment(word[i], 1);
		}
		std::cout << result << std::endl;
		std::cin >> n;
	}
}
