#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

const int MAX_N=100010;
// 1baseテ」ツ?ァs1,...,snテ」ツ?ョテ・ツ陳古」ツつ津ィツィツ暗ァツョツ?
class BIT{
private:
  ll bit[MAX_N];
  int n;
public:
  BIT(int sz){
    n=sz;
    memset(bit,0,sizeof(bit));
  }
  void init(){
    memset(bit,0,sizeof(bit));
  }
  ll sum(int i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
  // from-toテゥツ鳴禿」ツ?ョテァツキツ湘・ツ陳古」ツつ津ヲツアツづ」ツつ?」ツつ?
  ll rangeSum(int from,int to){
    ll res=0;
    res=sum(to)-sum(from-1);
    return res;
  }
  void add(int i,ll x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  // sumテ」ツ?ィaddテ」ツつ津ァツオツ?」ツ?ソテ・ツ青暗」ツつ湘」ツ?崚」ツ?ヲテ」ツ?（テ」ツ?ョテ・ツ?エテヲツ可?」ツ?ォxテ」ツ?ョテ・ツ?、テ」ツつ津、ツサツ」テ・ツ?・
  void insert(int i,ll x){
    add(i,-(sum(i)-sum(i-1))+x);
  }
};


int N,R;
int ss[51];
int ts[51];
int seq[100010];
ll fact[100010];
BIT bit(100010);
const int mod=1000000007;

int main(){
  fact[0]=1;
  for(int i=1;i<100010;i++)fact[i]=(fact[i-1]*i)%mod;
  while(cin>>N&&N){
    bit.init();
    for(int i=0;i<N;i++)seq[i]=i;
    cin>>R;
    for(int i=0;i<R;i++){
      cin>>ss[i]>>ts[i];
      ss[i]--,ts[i]--;
      swap(seq[ss[i]],seq[ts[i]]);
    }
    // テ、ツサツ甘・ツ崢榲ィツヲツ凝」ツつ凝ヲツ閉ーテ・ツュツ療」ツ?ョテ・ツ可催」ツ?ォテ」ツ??」ツ?湘」ツ?、テヲツ閉ーテ・ツュツ療」ツ?古」ツ?づ」ツつ凝」ツ?凝ヲツ閉ーテ」ツ?暗、ツクツ甘」ツ?津」ツ?ヲ
    // テ」ツ?敕」ツ?ョテヲツ閉ーテ・ツュツ療」ツ?ョテヲツ閉ー*(N-i-1)!テ」ツつ誕nsテ」ツ?ォ+
    ll ans=0;
    for(int i=0;i<N;i++){
      int all=seq[i];
      int cnt=all-bit.sum(seq[i]+1);
      //cout<<i<<" "<<all<<" "<<cnt<<endl;
      ans=(ans+(ll)cnt*fact[(N-i-1)])%mod;
      bit.add(seq[i]+1,1);
    }
    cout<<ans<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3120