#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll MOD = (ll)1e9 + 7;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

ll R9 = rev(9);

ll ans = 0;
map<int, vector<int>> g;
map<int, int> col;
vector<pii> ord;
vector<ll> vals;
int id[40];
int n, q;
int m = 0;
ll f[11];
ll rf[11];
ll dp[11][(1 << 15) + 5];

struct Edge {
	int to;
	ll w1, w2;

	Edge() : to(-1), w1(1), w2(1) {}
	Edge(int _to, ll _w1, ll _w2) : to(_to), w1(_w1), w2(_w2) {}
};

vector<Edge> G[20];

void addEdge(int v, int to, ll w) {
	if (v < to) swap(v, to);
//	cerr << "addEdge " << v << " " << to << " " << w << endl;
	for (int i = 0; i < (int)G[v].size(); i++) {
		if (G[v][i].to != to) continue;
		G[v][i].w1 = mult(G[v][i].w1, w);
		G[v][i].w2 = mult(G[v][i].w2, w + 1);
		return;
	}
	G[v].push_back(Edge(to, w, (w + 1) % MOD));
}

ll calc() {
	ll res = 1;
	for (int i = 0; i < q - 1; i++) {
		if (id[ord[i].second] == id[ord[i + 1].second])
			res = mult(res, vals[i] + 1);
		else
			res = mult(res, vals[i]);
	}
	return res;
}

void brute(int pos, int mx, ll w) {
	if (pos == m) {
//		cerr << f[mx] << " " << w << endl;
//		ans = add(ans, mult(f[mx], calc()));
		ans = add(ans, mult(f[mx], w));
		return;
	}
	for (int x = 0; x <= min(8, mx); x++) {
		id[pos] = x;
		ll nw = w;
		for (Edge e : G[pos]) {
			if (id[e.to] == x)
				nw = mult(nw, e.w2);
			else
				nw = mult(nw, e.w1);
		}
		brute(pos + 1, max(mx, x + 1), nw);
	}
}

void dfs(int v) {
	col[v] = m;
	for (int u : g[v]) {
		if (col.count(u) == 0)
			dfs(u);
	}
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	rf[0] = 1;
	for (int i = 1; i <= 9; i++)
		rf[i] = mult(rf[i - 1], rev(i));

	f[0] = f[1] = 1;
	for (int i = 1; i < 9; i++) {
		f[i + 1] = mult(f[i], 9 - i);
	}

	scanf("%d%d", &n, &q);
	while(q--) {
		int l, r;
		scanf("%d%d", &l, &r);
		l--;
		g[l].push_back(r);
		g[r].push_back(l);
	}
	for (auto t : g) {
		int x = t.first;
		if (col.count(x) == 0) {
			dfs(x);
			m++;
		}
	}
	for (auto t : col)
		ord.push_back(t);
	sort(ord.begin(), ord.end());
	q = (int)ord.size();
	for (int i = 1; i < q; i++) {
		int L = ord[i].first - ord[i - 1].first;
		ll w = mult(R9, sub(bin_pow(10, L), 1));
		vals.push_back(w);
//		addEdge(ord[i].second, ord[i - 1].second, w);
	}
/*
	for (ll x : vals)
		cerr << x << " ";
	cerr << endl;
*/
//	brute(0, 0, 1);

	dp[0][0] = 1;

	for (int mask = 1; mask < (1 << m); mask++) {
		for (int nmask = mask; nmask > 0; nmask = (nmask - 1) & mask) {
			int smask = mask ^ nmask;
			ll w = 1;
			for (int i = 0; i < q - 1; i++) {
				int v = ord[i].second, u = ord[i + 1].second;
				if ((smask >> v) & 1) v = 0;
				else if ((nmask >> v) & 1) v = 1;
				else v = 2;
				if ((smask >> u) & 1) u = 0;
				else if ((nmask >> u) & 1) u = 1;
				else u = 2;
				if (v != 1 && u != 1) continue;
				if (v == 2 || u == 2) continue;
				if (v == 1 && u == 1)
					w = mult(w, vals[i] + 1);
				else
					w = mult(w, vals[i]);
			}
			for (int pos = 1; pos <= 9; pos++) {
				ll nw = mult(dp[pos - 1][smask], w);
				if (pos > 1) nw = mult(nw, 10 - pos);
				dp[pos][mask] = add(dp[pos][mask], nw);
			}
		}
	}

	for (int pos = 1; pos <= 9; pos++) {
		ans = add(ans, mult(dp[pos][(1 << m) - 1], rf[pos]));
	}

	ans = mult(ans, bin_pow(10, n - (ord.back().first - ord[0].first)));
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 2560