#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int Mod=1e9+7;
int n,m;
bool f=1;
int read()
{
	int p=1,ans=0;
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar())
	if(ch=='-') p=-1;
	ans=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar())
	ans=(ans<<1)+(ans<<3)+ch-'0';
	return ans*p;
}
void solve1()
{
	long long ans=1,sk=1;
	for(int i=1;i<=n-3;i++)
	ans=ans*2%Mod;
	ans=ans*n%Mod*(n-1)%Mod;
	if(n==2) ans=1;
	if(n==1) ans=0;
	for(int i=1;i<n;i++)
	sk=sk*2%Mod;
	printf("%lld\n",(ans+sk*n%Mod)%Mod);
}
int main()
{
	freopen("barrack.in","r",stdin);
	freopen("barrack.out","w",stdout);
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
	}
	if(m==n-1) solve1();
	//else solve2();
	fclose(stdin);
	fclose(stdout);
	return 0;
}