#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 5e5 + 10;
const int mod = 1e9 + 7;
int h[N], e[N], ne[N], dp[N];
int indx = 0;
int n, m;
int dist[5010][5010];
ll res = 0;

void add(int a, int b){
	e[indx] = b; ne[indx] = h[a]; h[a] = indx ++;
}
bool vis[N];
void BFS(int x){
	int q[N];
	int hh = 0, tt = 0;
	dist[x][x] = 0; vis[x] = 1;
	q[0] = x;
	while(hh <= tt){
		int u = q[hh ++];
		for(int i = h[u]; ~i; i ++){
			int v = e[u];
			if(!vis[v]){
				dist[x][v] = dist[x][u] + 1;
				q[++tt] = v;
				vis[v] = 1;
			}
		}
	}
}

ll kasumi(int a, int b){
	ll ans = 1, base = a;
	while(b){
		if(b&1) ans = ans * base % mod;
		base = base * base % mod;
		b >>= 1;
	}
	return ans;
}

int main(){
	freopen("barrack.in", "r", stdin);
	freopen("barrack.out", "w", stdout);
	
	memset(h, -1, sizeof h);
	scanf("%d%d", &n, &m);
	
	int from, to;
	for(int i = 1; i <= m; i ++){
		scanf("%d%d", &from, &to);
		add(from, to);
	}
	for(int i = 1; i <= n; i ++)
		BFS(i);
	res = n * kasumi(2, m) - 1;
	
//	if(m == n - 1){
//		BFS(1);
//		for(int i = 1; i <= n; i ++)
//			
//	}
	printf("%lld \n", res);
	return 0;
}

/*
tuibuchulaishizi
baile
diertihedisantidoumeiyousilu
disitishiqujianDPma?
wobuqingchu
xieleyigeSEGEMNT_TREEdebaoli,
diyitidaleO(N^4)debaoli
zhihuiyouhuaCdeqingkuang
Fdeqingkuangtuibuchulai
*/