神tm st表+并查集
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
int n, m, a, b, c, d, fa[19][100005];
const int mod=1000000007;
int myfind(int p, int x){
return fa[p][x]==x?x:fa[p][x]=myfind(p, fa[p][x]);
}
void merge(int p, int x, int y){
int u=myfind(p, x), v=myfind(p, y);
if(u==v) return ;
fa[p][v] = u;
if(p==0) return ;
merge(p-1, x, y);
merge(p-1, x+(1<<(p-1)), y+(1<<(p-1)));
}
int main(){
cin>>n>>m;
if(n==1){
printf("10\n");
return 0;
}
for(int i=0; i<=17; i++)
for(int j=1; j<=n; j++)
fa[i][j] = j;
while(m--){
scanf("%d %d %d %d", &a, &b, &c, &d);
if(a>c){
swap(a, c);
swap(b, d);
}
int t=log2(b-a+1);
merge(t, a, c);
merge(t, b-(1<<t)+1, d-(1<<t)+1);
}
int t=0, ans=9;
for(int i=1; i<=n; i++)
if(myfind(0, i)==i)
t++;
for(int i=1; i<t; i++)
ans = (ll)ans * 10 % mod;
cout<<ans<<endl;
return 0;
}