#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <string>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define REP(i, x, y) for(int i = (int)x; i <= (int)y; i ++)
#define FOR(i, x, y) for(int i = (int)x; i <  (int)y; i ++)
#define PER(i, x, y) for(int i = (int)x; i >= (int)y; i --)
#define trace(x) cerr << #x << " " << x << endl;
#define dprintf(...) fprintf(stderr, __VA__ARGS__)
#define dln()        fprintf(stderr, "\n")
using namespace std;
typedef long long LL;
typedef long double db;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
const	int N = 100005;
const	int P = 1e9 + 7;
const	int inf = 1e9;
const	LL Inf = 1e15;

inline int IN(){
	char ch = getchar(); int x = 0, f = 0;
	while(ch < '0' || ch > '9') ch = getchar(), f = (ch == '-');
	while(ch >= '0' && ch <= '9'){
		x = (x << 1) + (x << 3) + ch - 48;
		ch = getchar();
	}
	return f ? (-x) : x;
}

inline int Pow(int x, int y, int p){
	int an = 1;
	for(; y; y >>= 1, x = (LL)x * x % p) if(y & 1) an = (LL)an * x % p;
	return an;
}

void renew(int &x, int y){
	x += y;
	if(x < 0) x += P;
	else if(x >= P) x -= P;
}

void setIO(string a){
#ifndef LOCAL
	freopen((a + ".in").c_str(), "r", stdin);
	freopen((a + ".out").c_str(), "w", stdout);
#else
	freopen("1.in", "r", stdin);
	freopen("1.out", "w", stdout);
#endif
}

template<typename T> inline void chkmin(T &a, const T &b) {if(a > b) a = b;}
template<typename T> inline void chkmax(T &a, const T &b) {if(a < b) a = b;}

int cnt[16][16], sg[16];
int x1[16], x2[16], x3[16], tmp[16], tmp1[16], tmp2[16], s3[20];
int n, m, ans, out[16];
int fg, p2[100005];
VI e[N];
int e13, e23, xda, bb[100005];

void dfs(int x, int ways){
	if(x == 3 || n == 3){
		REP(i, 0, n) x1[i] = x2[i] = x3[i] = tmp1[i] = tmp2[i] = tmp[i] = 0;
		if(n == 3){
			x3[0] = 1;
		}else{
			for(auto v : e[x]) tmp[sg[v]] ++;
			int kk = out[3], nways = ways;
			REP(i, 0, n){
				kk -= tmp[i];
				x3[i] = (LL)nways * p2[kk] % P;
				if(!tmp[i]) break;
				nways = (LL)nways * (p2[tmp[i]] - 1) % P;
			}
		}
		s3[n + 1] = 0;
		PER(i, n, 0){
			s3[i] = (s3[i + 1] + x3[i] >= P ? s3[i + 1] + x3[i] - P : s3[i + 1] + x3[i]);
		}
		for(auto v : e[1]) tmp1[sg[v]] ++;
		for(auto v : e[2]) tmp2[sg[v]] ++;
		int k1 = out[1], k2 = out[2], nways = 1, sum = 0;
		REP(i, 0, n){
			k1 -= tmp1[i];
			k2 -= tmp2[i];
			int fck = (LL)nways * p2[k1 + k2] % P;
			ans = (ans + (LL)fck * (1LL * xda * s3[i + 1] + x3[i] + sum)) % P;
			if(!tmp1[i] || !tmp2[i]){
				if((e13 || tmp1[i]) && (e23 || tmp2[i])){
					nways = (LL)nways * x3[i] % P;
					if(tmp1[i] && e13) nways = (LL)nways * (p2[tmp1[i] + 1] - 1) % P;
					if(tmp2[i] && e23) nways = (LL)nways * (p2[tmp2[i] + 1] - 1) % P;
					REP(ii, i + 1, n){
						k1 -= tmp1[ii];
						k2 -= tmp2[ii];
						ans = (ans + (LL)nways * p2[k1 + k2]) % P;
						if(!tmp1[ii] || !tmp2[ii]) break;
						nways = (LL)nways * (p2[tmp1[ii]] - 1) % P * (p2[tmp2[ii]] - 1) % P;
					}
				}
				break;
			}
			nways = (LL)nways * (p2[tmp1[i]] - 1) % P * (p2[tmp2[i]] - 1) % P;
			sum = (sum + (LL)x3[i] * (e13 ? bb[tmp1[i]] : 1) % P * (e23 ? bb[tmp2[i]] : 1)) % P;
		}

		return;
	}
	int lim = n - x, *a = cnt[x];
	REP(i, 0, lim) a[i] = 0;
	for(auto v : e[x]) a[sg[v]] ++;
	int nways = ways, kk = out[x];
	REP(i, 0, lim){
		sg[x] = i;
		kk -= a[i];
		dfs(x - 1, (LL)nways * p2[kk] % P);
		if(!a[i]) break;
		nways = (LL)nways * (p2[a[i]] - 1) % P;
	}
}

int main(){

	scanf("%d%d", &n, &m);
	*p2 = 1;
	REP(i, 1, n * n) p2[i] = (p2[i - 1] + p2[i - 1]) % P;
	REP(i, 1, n * n) bb[i] = (LL)(p2[i + 1] - 1) * Pow(p2[i] - 1, P - 2, P) % P;
	REP(i, 1, m){
		int x, y;
		scanf("%d%d", &x, &y);
		if(x == 1 && y == 3){
			e13 = 1;
			continue;
		}
		if(x == 2 && y == 3){
			e23 = 1;
			continue;
		}
		if(x == 1 && y == 2){
			fg = 1;
			continue;
		}
		e[x].pb(y);
		out[x] ++;
	}

	xda = p2[e13 + e23];

	if(n == 2){
		cout << 1 << endl;
		return 0;
	}

	sg[n] = 0;
	dfs(n - 1, 1);

	ans = (p2[m] - ans + P) % P;
	cout << ans << endl;

	return 0;
}






















Measured memory_bytes: 2688