#include<bits/stdc++.h>
using namespace std;

const int Mode = 1e9+7;

int c(int k){
	int ret=1;
	for(int i=1; i<=k; i++) ret*=2,ret%=Mode;
	return ret;
}

int main(){
	freopen("barrack.in","r",stdin);
	freopen("barrack.out","w",stdout);
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1; i<=m; i++){
		int a,b;
		scanf("%d %d",&a,&b);
	}
	if(m==n-1) cout<<(n-2+2*c(m))%Mode;
	else cout<<n*m;
}