#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 10007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,k;
int a[10],b[10];
int x[35];
bool used[35];
ll dp[55][55][2],f;
int main(){
	cin >> n >> k;
	for(int i=0;i<k;i++) cin >> a[i] >> b[i];
	ll ans = 0;
	for(int mask=0;mask<(1<<k);mask++){
		for(int i=0;i<n;i++) x[i] = -1, used[i] = 0;
		bool bad = 0;
		for(int i=0;i<k;i++){
			if(((mask>>i)&1)){
				if(x[a[i]] != -1 && x[a[i]] != b[i]) bad = 1;
				if(used[b[i]]) bad = 1;
				x[a[i]] = b[i];
				used[b[i]] = 1;
			}
		}
		if(bad) continue;
		ll val = 0;
		//not consider both lines
		int C = 0;
		for(int i=0;i<n;i++) if(x[i] == -1) C++;
		ll mm = 1;
		for(int i=1;i<=C;i++) mm = mm*1LL*i%mod;
		val = (val+mm)%mod;
		//consider only one line (x = y)
		memset(dp,0LL,sizeof(dp));
		dp[0][0][0] = 1;
		for(int i=0;i<n;i++){
			for(int j=0;j<=i;j++){
				if(x[i] == i || (!used[i] && x[i] == -1)){
					rep(q,2) dp[i+1][j][1-q] = (dp[i+1][j][1-q]+dp[i][j][q])%mod;
				}
			    {
					int add = (x[i] == -1);
					rep(q,2) dp[i+1][j+add][q] = (dp[i+1][j+add][q]+dp[i][j][q])%mod;
				}
			}
		}
		f = 1;
		for(int i=0;i<=n;i++){
			val -= dp[n][i][0] * f % mod;
			val += dp[n][i][1] * f % mod;
			f = f*1LL*(i+1)%mod;
		}
		//consider only one line (x+y = n-1)
		memset(dp,0LL,sizeof(dp));
		dp[0][0][0] = 1;
		for(int i=0;i<n;i++){
			for(int j=0;j<=i;j++){
				if(x[i] == n-1-i || (!used[n-1-i] && x[i] == -1)){
					rep(q,2) dp[i+1][j][1-q] = (dp[i+1][j][1-q]+dp[i][j][q])%mod;
				}
				{
					int add = (x[i] == -1);
					rep(q,2) dp[i+1][j+add][q] = (dp[i+1][j+add][q]+dp[i][j][q])%mod;
				}
			}
		}
		f = 1;
		for(int i=0;i<=n;i++){
			val -= dp[n][i][0] * f % mod;
			val += dp[n][i][1] * f % mod;
			f = f*1LL*(i+1)%mod;
		}
		//consider both lines (x = y & x+y = n-1)
		memset(dp,0LL,sizeof(dp));
		dp[0][0][0] = 1;
		int last = 0;
		for(int i=0;i<=n-1-i;i++){
		    last = i+1;
			for(int j=0;j<=2*i;j++){
				//i & n-1-i
				//both
				if(i != n-1-i){
					if(x[i] != -1 && x[i] != i && x[i] != n-1-i) goto nxt;
					if(x[n-1-i] != -1 && x[n-1-i] != i && x[n-1-i] != n-1-i) goto nxt;
					bool fail = 0;
					for(int k=0;k<n;k++) if(k != i && k != n-1-i && (x[k] == i || x[k] == n-1-i)) fail = 1;
					if(fail) goto nxt;
					int mul = 2;
					if(x[i] != -1 || x[n-1-i] != -1) mul = 1;
					rep(q,2) dp[i+1][j][q] = (dp[i+1][j][q]+dp[i][j][q]*1LL*mul)%mod;
				}
				nxt:;
				if(i != n-1-i){
					if(x[i] != -1 && x[i] != i && x[i] != n-1-i) goto nxt2;
					int fail = 0;
					for(int k=0;k<n;k++) if(k != i && (x[k] == i || x[k] == n-1-i)) fail += 1;
					if(fail == 2) goto nxt2;
					int add = (x[n-1-i] == -1);
					int mul = 2-fail;
					if(x[i] != -1) mul = 1;
					rep(q,2) dp[i+1][j+add][1-q] = (dp[i+1][j+add][1-q]+dp[i][j][q]*1LL*mul)%mod;
				}
				else{
				    if(x[i] != -1 && x[i] != i) goto nxt2;
					int fail = 0;
					for(int k=0;k<n;k++) if(k != i && (x[k] == i)) fail += 1;
					if(fail == 1) goto nxt2;
					int add = 0;
					int mul = 1;
					rep(q,2) dp[i+1][j+add][1-q] = (dp[i+1][j+add][1-q]+dp[i][j][q]*1LL*mul)%mod;
				}
				nxt2:;
				if(i != n-1-i){
					if(x[n-1-i] != -1 && x[n-1-i] != i && x[n-1-i] != n-1-i) goto nxt3;
					int fail = 0;
					for(int k=0;k<n;k++) if(k != n-1-i && (x[k] == i || x[k] == n-1-i)) fail += 1;
					if(fail == 2) goto nxt3;
					int add = (x[i] == -1);
					int mul = 2-fail;
					if(x[n-1-i] != -1) mul = 1;
					rep(q,2) dp[i+1][j+add][1-q] = (dp[i+1][j+add][1-q]+dp[i][j][q]*1LL*mul)%mod;
				}
				nxt3:;
				if(i != n-1-i){
					int add = (x[i] == -1) + (x[n-1-i] == -1);
					rep(q,2) dp[i+1][j+add][q] = (dp[i+1][j+add][q]+dp[i][j][q])%mod;
				}
				else{
				    int add = (x[i] == -1) ;
					rep(q,2) dp[i+1][j+add][q] = (dp[i+1][j+add][q]+dp[i][j][q])%mod;
				}
			}
		}
		f = 1;
		for(int i=0;i<=n;i++){
			val += dp[last][i][0] * f % mod;
			val -= dp[last][i][1] * f % mod;
			f = f*1LL*(i+1)%mod;
		}
		if(__builtin_popcount(mask)%2 == 0) ans = (ans+val)%mod;
		else ans = (ans-val)%mod;
	}
	cout << (ans+mod)%mod << endl;
}


Measured memory_bytes: 3164