#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,m,u[1000005],v[1000005];
vector<int> to[500005];
ll mod=1e9+7,f[500005][3];
void solveA(){
	ll ans=1;
	for(int i=1;i<=n-2;i++){
		ans=ans*2%mod;
	}
	ll N=n;
	ans=ans*((N*(N+3)/2)%mod)%mod;
	printf("%lld",ans);
}
void dfs(int now,int fa){
	int si=to[now].size();
	f[now][0]=1;
	f[now][1]=1;
	f[now][2]=1;
	for(int e=0;e<si;e++){
		int v=to[now].at(e);
		if(v==fa)continue;
		dfs(v,now);
		f[now][0]=f[now][0]*f[v][0]*2%mod;
		f[now][1]=f[now][1]*(f[v][1]+f[v][0]*2)%mod;
		f[now][2]=(f[now][2]+f[v][2]*2)%mod;
	}
	f[now][1]*=2;
	f[now][1]-=f[now][0];
	f[now][1]%=mod;
}
void solve1(){
	for(int i=1;i<=m;i++){
		int x=u[i],y=v[i];
		to[x].push_back(y);
		to[y].push_back(x);
	}
	dfs(1,0);
	printf("%lld",(f[1][1]+f[1][2]+mod+mod)%mod);
}
int main(){
	freopen("barrack.in","r",stdin);
	freopen("barrack.out","w",stdout);
	scanf("%d%d",&n,&m);
	if(n==1){
		printf("1");
		return 0;
	}
	bool subA=(m==n-1);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u[i],&v[i]);
		if(v[i]!=i+1||u[i]!=i)subA=0;
	}		
	if(subA){
		solveA();
		return 0;
	}
	if(m==n-1){
		solve1();
		return 0;
	}
	return 0;
}
