#include <bits/stdc++.h>
using namespace std;
void solve();
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed;
  cout.precision(12);
  solve();
  return 0;
}
template <typename T>
void sc(T& x) {
  cin >> x;
}
template <typename Head, typename... Tail>
void sc(Head& head, Tail&... tail) {
  cin >> head;
  sc(tail...);
}
template <typename T>
void pr(const T& x) {
  cout << x << '\n';
}
template <typename Head, typename... Tail>
void pr(const Head& head, const Tail&... tail) {
  cout << head << ' ';
  pr(tail...);
}
template <typename... T>
void err(const T&... cod) {
  pr(cod...);
  exit(0);
}
const int mod = 1e9 + 7;
int mult(int x, int y) { return (1LL * x * y) % mod; }
void add(int& x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
void sub(int& x, int y) {
  x -= y;
  if (x < 0) x += mod;
}
void solve() {
  int n, m;
  sc(n, m);
  map<int, vector<int>> ma;
  bool ok = false;
  for (int i = 0; i < m; i++) {
    int l, r;
    sc(l, r);
    ma[r].push_back(l);
    ok |= (l == 0);
  }
  vector<int> idxs;
  idxs.push_back(0);
  for (auto p : ma) idxs.push_back(p.first);
  vector<int> dp(((int)idxs.size()), 0);
  dp[0] = ok;
  int sum = ok, ans = 0, idxr = 1;
  for (auto p : ma) {
    int r = p.first;
    vector<int> v = p.second;
    dp[idxr] = sum;
    int ways = mult(((int)v.size()), sum);
    for (int l : v) {
      int idxl = lower_bound(idxs.begin(), idxs.end(), l) - idxs.begin() - 1;
      if (l > 0) sub(ways, dp[idxl]);
    }
    add(dp[idxr], ways);
    add(sum, ways);
    if (r == n) ans = ways;
    idxr++;
  }
  pr(ans);
}
