#include <bits/stdc++.h>
#define dbg() cerr <<
#define name(x) (#x) << ": " << (x) << ' ' <<
// cat de prost sa fii sa faci aceeasi greseala si in brut si in solutia buna?
using namespace std;

const int MOD = (int)1e9 + 7;

int Pow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) ret = 1LL * ret * b % MOD;
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return ret;
}

const long long INV9 = Pow(9, -1);

int Solve(int n, const vector<int> &v, 
  const vector<pair<int, int>> &interv) {

  auto Norm = [&](int x) {
    int pos = lower_bound(v.begin(), v.end(), x) - v.begin();
    assert(v[pos] == x);
    return pos;
  };

  vector<vector<int>> adj(v.size());
  for (auto &p : interv) {
    int x = Norm(p.first), y = Norm(p.second);
    adj[x].emplace_back(y);
    adj[y].emplace_back(x);
  }

  vector<bool> vis(v.size());
  function<void(int, int&)> DFS = [&](int node, int &mask) {
    mask |= 1 << node;
    vis[node] = true;
    for (int &x : adj[node]) {
      if (!vis[x]) {
        DFS(x, mask);
      }
    }
  };

  auto Calc = [&](int len) {
    return 1LL * (Pow(10, len) - 1 + MOD) * INV9 % MOD;
  };

  vector<int> groups;
  for (int i = 0; i < (int)v.size(); ++i) {
    if (!vis[i]) {
      groups.emplace_back();
      DFS(i, groups.back());
    }
  }

  auto GetCoef = [&](int mask) {
    vector<int> pos;
    for (int i = 0; (1 << i) <= mask; ++i) {
      if (mask & (1 << i)) {
        pos.emplace_back(i);
      }
    }
    int coef = 1;
    for (int i = 1; i < (int)pos.size(); ++i) {
      int x = pos[i - 1], y = pos[i];
      if (x + 1 != y) continue;
      int den = Calc(v[y] - v[x]);
      coef = 1LL * coef * Pow(den, -1) % MOD;
      coef = 1LL * coef * (den + 1) % MOD;
    }
    return coef;
  };
  
  int m = groups.size();
  vector<int> coef(1 << m), meta_mask(1 << m);
  for (int meta = 1; meta < (1 << m); ++meta) {
    int &mask = meta_mask[meta];
    for (int i = 0; i < m; ++i) {
      if (meta & (1 << i)) {
        mask |= groups[i];
      }
    }
    coef[meta] = GetCoef(mask);
  }
  
  auto dp = coef; // for color 0
  for (int color = 1; color < 9; ++color) {
    for (int meta = (1 << m) - 1; meta > 0; --meta) {
      for (int sub = (meta - 1) & meta; sub > 0; sub = (sub - 1) & meta) {
        int oth = meta ^ sub;
        // we need to force the block before min_l to be colored with color 0
        if (oth & 1) continue;
        (dp[meta] += 1LL * dp[sub] * coef[oth] % MOD) %= MOD;
      }
    }
  }
  int ans = 1LL * Pow(10, v[0]) * Pow(10, n - v.back()) % MOD;
  for (int i = 1; i < (int)v.size(); ++i) {
    ans = 1LL * ans * Calc(v[i] - v[i - 1]) % MOD;
  }
  ans = 1LL * ans * dp[(1 << m) - 1] % MOD;
  return ans;
}

void Read(int &n, int &q, vector<pair<int, int>> &interv) {
  cin >> n >> q;
  interv.resize(q);
  for (auto &p : interv) {
    cin >> p.first >> p.second; --p.first;
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, q;
  vector<pair<int, int>> interv;
  Read(n, q, interv);

  vector<int> v(2 * q);
  int min_l = (int)1e9 + 5, max_r = -1;
  for (int i = 0; i < q; ++i) {
    int l, r; tie(l, r) = interv[i];
    min_l = min(min_l, l);
    max_r = max(max_r, r);
    v[i] = l;
    v[i + q] = r;
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  
  cout << Solve(n, v, interv) << endl;
}

Measured memory_bytes: 640