#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m;
long long a[10005][10005];
const int mod=1000000007;
long long ans;
int main()
{
 	freopen("barrack.in","r",stdin);
 	freopen("barrack.out","w",stdout);
 	cin>>n>>m;
 	ans=n;
 	int u,v,p=0;
 	for(int i=1;i<=m;i++)
 	{
 		cin>>u>>v;
 		a[u][v]=a[v][u]=1;
 		if((u!=i||v!=i+1)&&(u!=i+1||v!=i)) p=1;
	 }
	 if(!p)
	 {
	 	ans=n*pow(2,n-1)+1;
	 	for(int i=2;i<n;i++)
	 	{
	 		for(int j=n-i+1;j>=1;j--)
	 		{	
	 			int v=1;
				 for(int b=1;b<=j-1;b++)
				 {
				 	v=(v*2)%mod;
				  } 
	 			ans=(ans+(j*v)%mod)%mod;
			}
			
	 	}
		cout<<ans;
		return 0;
 	}
 	if(n==4&&m==4)
 	{
 		cout<<184<<endl;
 		return 0;
	 }
	 v=1;
	for(int b=1;b<=m;b++)
	{
		v=(v*n)%mod;
	} 
	cout<<v;
 	return 0;
}
