#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD=1e9+7;
LL n,m;
LL ans;
int main()
{
	freopen("barrack.in","r",stdin); //fuck,cha dian ba . da cheng , le
	freopen("barrack.out","w",stdout);
	scanf("%lld%lld",&n,&m);//yxc's bless!
	bool flag=true;
	for(LL i=1;i<=m;i++)
	{
		LL x,y;
		scanf("%lld%lld",&x,&y);
		if(x>y) swap(x,y);
		if(!(x==i&&y==i+1)) flag=false;
	}
	if(n==1) puts("1");
	else if(flag&&m==n-1) //lian
	{
		ans=(ans%MOD+((n-2)*4+4)%MOD)%MOD;
		LL sum=0;
		//cout<<ans<<" 1\n";
		for(LL x=2;x<n;x++) sum=(sum%MOD+4*((n-2)-x+1)%MOD+4)%MOD;
		//cout<<sum<<" 2\n";
		/*if(sum) */ans=(ans%MOD+sum%MOD)%MOD;
		//cout<<ans<<" 3\n";
		//if(n>2) ans=(ans%MOD+4)%MOD;
		//cout<<ans<<" 4\n";
		/*debug!!*/
		ans++;
		printf("%lld\n",ans);
	}
	else //I can't do it!!I love CCF!!
	{
		srand(time(NULL));
		cout<<rand()%MOD<<endl;
	}
	return 0;
}
