#include<bits/stdc++.h> #define LOG 20 #define MAX_N 100000 #define MOD 1000000007 usingnamespace std; typedeflonglong lnt; template <classT> inlinevoidread(T &x){ x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0'); } int n, m, cnt, LOG2[MAX_N+5], fa[LOG][MAX_N+5]; lnt ans = 9LL; intgetf(int d, int x){return fa[d][x] == x ? x : fa[d][x] = getf(d, fa[d][x]);} intmain(){ read(n), read(m); for (int i = 2; i <= n; i++) LOG2[i] = LOG2[i>>1]+1; for (int i = 0; i < LOG; i++) for (int j = 1; j <= n; j++) fa[i][j] = j; for (int i = 0, l1, l2, e1, e2, l, d; i < m; i++) { read(l1), read(e1), read(l2), read(e2), l = e1-l1+1, d = LOG2[l]; if (getf(d, l1)^getf(d, l2)) fa[d][fa[d][l1]] = fa[d][l2]; if (getf(d, l1+l-(1<<d))^getf(d, l2+l-(1<<d))) fa[d][fa[d][l1+l-(1<<d)]] = fa[d][l2+l-(1<<d)]; } for (int i = LOG2[n]; i; i--) for (int j = 1; j <= n-(1<<i)+1; j++) { if (getf(i-1, j)^getf(i-1, getf(i, j))) fa[i-1][fa[i-1][j]] = fa[i-1][fa[i][j]]; if (getf(i-1, j+(1<<(i-1)))^getf(i-1, getf(i,j)+(1<<(i-1)))) fa[i-1][fa[i-1][j+(1<<(i-1))]] = fa[i-1][fa[i][j]+(1<<(i-1))]; } for (int i = 1; i <= n; i++) if (getf(0, i) == i) cnt++; for (int i = 1; i < cnt; i++) (ans *= 10LL) %= MOD; returnprintf("%lld\n", ans), 0; }