#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7,n,m,u,v,ans;
int main()
{
	freopen("barrack.in","r",stdin);
	freopen("barrack.out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>u>>v;
	}
	if(m==n-1)
	{
		if(n==2)ans=5;
		if(n==3)ans=9;
		cout<<ans%mod;
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}