#include<cstdio>
#include<cctype>
#include<queue>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c==‘-‘) f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-‘0‘;
return x*f;
}
typedef long long ll;
const int maxn=100010;
int n,m,A[maxn],pa[maxn*20],s[maxn*20],Log[maxn];
int id(int k,int x) {return k*n+x;}
int findset(int x) {return pa[x]==x?x:findset(pa[x]);}
void merge(int x,int y,int k) {
int f1=findset(id(k,x)),f2=findset(id(k,y));
if(f1!=f2) {
if(s[f1]>s[f2]) swap(f1,f2);
pa[f1]=f2;if(s[f1]==s[f2]) s[f2]++;
if(k) merge(x,y,k-1),merge(x+(1<<k-1),y+(1<<k-1),k-1);
}
}
int main() {
n=read();m=read();
for(int i=0;(1<<i)<=n;i++) rep(j,1,n) pa[id(i,j)]=id(i,j),s[id(i,j)]=1;
Log[0]=-1;rep(i,1,n) Log[i]=Log[i>>1]+1;
rep(i,1,m) {
int a=read(),b=read(),c=read(),d=read(),k=Log[b-a+1];
merge(a,c,k);merge(b-(1<<k)+1,d-(1<<k)+1,k);
}
int cnt=0;
rep(i,1,n) A[i]=findset(id(0,i));
sort(A+1,A+n+1);
rep(i,1,n) if(A[i]!=A[i-1]) cnt++;
if(cnt==1) puts("10");
else {
ll ans=9;
rep(i,1,cnt-1) (ans*=10)%=1000000007;
printf("%lld\n",ans);
}
return 0;
}