#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
#define unl unsigned long long
#define inf 1e9
#define eps 1e-8
#define md 1000000007
#define N 100010
using namespace std;
unl tmp[4*N],mi[N],ha[4*N];
int fa[N];
int lx[4*N],rx[4*N];
vector<int> vec[N];
const unl cheng=23333333;
void build(int i,int l,int r)
{
tmp[i]=mi[r-l+1]; lx[i]=l; rx[i]=r;
if (l==r) { ha[i]=fa[l]; return;}
int mid=(l+r)>>1;
build(i<<1,l,mid); build(i<<1|1,mid+1,r);
ha[i]=ha[i<<1]*tmp[i<<1]+ha[i<<1|1];
}
void modify(int i,int x)
{
if (lx[i]==rx[i]) { ha[i]=fa[x]; return;}
int mid=(lx[i]+rx[i])>>1;
if (x<=mid) modify(i<<1,x); else modify(i<<1|1,x);
ha[i]=ha[i<<1]*tmp[i<<1]+ha[i<<1|1];
}
unl query(int i,int ql,int qr)
{
if (ql<=lx[i]&&rx[i]<=qr) return ha[i];
int mid=(lx[i]+rx[i])>>1;
if (qr<=mid) return query(i<<1,ql,qr);
if (mid+1<=ql) return query(i<<1|1,ql,qr);
return query(i<<1,ql,mid)*mi[mid-ql+1]+query(i<<1|1,mid+1,qr);
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++) { fa[i]=i; vec[i].push_back(i);}
mi[0]=1; for (int i=1;i<=n;i++) mi[i]=mi[i-1]*cheng;
build(1,1,n);
for (int i=1;i<=m;i++)
{
int l1,r1,l2,r2;
scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
while (query(1,l1,r1)!=query(1,l2,r2))
{
int L=0,R=r1-l1;
while (L!=R)
{
int mid=(L+R)>>1;
if (query(1,l1,l1+mid)!=query(1,l2,l2+mid)) R=mid; else L=mid+1;
}
int f1=fa[l1+L],f2=fa[l2+L];
if (vec[f1].size()<vec[f2].size()) swap(f1,f2);
for (int j=vec[f2].size()-1;j>=0;j--)
{
int x=vec[f2][j];
fa[x]=f1; modify(1,x);
vec[f1].push_back(x);
}
vec[f2].clear();
}
}
int k=0;
for (int i=1;i<=n;i++) if (fa[i]==i) k++;
ll ans=9;
for (int i=2;i<=k;i++) ans=ans*10%md;
printf("%lld\n",ans);
return 0;
}