#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
const int N=1e6+10;
int n,m;
int nxt[N],to[N],head[N];
int A;
long long read()
{
	long long f=1,x=0;
	char q=getchar();
	while(q<'0'||q>'9')
	{
		if(q=='-') f=-1;
		q=getchar();
	}
	while(q>='0'&&q<='9')
	{
		x=x*10+q-'0';
		q=getchar();
	}
	return x*f;
}
int main()
{
	freopen("barrack.in","r",stdin);
	freopen("barrack.out","w",stdout);
	n=read();
	m=read();
	A=1;
	for(int i=1,u_,v_;i<=m;i++)
	{
		u_=read();
		v_=read();
		if((u_!=i||v_!=i+1)&&(u_!=i+1|v_!=i)) A=0;
	}
		cout<<n*(n+1)/2%mod<<endl;//
	return 0;
}
//rp++
