#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, mod = 1e9 + 7, dp[1000005], sum[1000005];
vector<int> bi[1000005];
struct ii {
  int l, r;
} a[1000005];
vector<int> all;
bool cmp(ii x, ii y) { return x.r < y.r; }
int main() {
  scanf("%d%d", &n, &m);
  all.push_back(0);
  all.push_back(n);
  for ((i) = 1; (i) <= (m); (i)++) {
    scanf("%d%d", &a[i].l, &a[i].r);
    all.push_back(a[i].l);
    all.push_back(a[i].r);
  }
  sort(all.begin(), all.end());
  all.resize(unique(all.begin(), all.end()) - all.begin());
  sort(a + 1, a + m + 1, cmp);
  dp[1] = sum[1] = 1;
  int t = 1;
  for ((i) = 1; (i) <= (m); (i)++) {
    a[i].l = upper_bound(all.begin(), all.end(), a[i].l) - all.begin();
    a[i].r = upper_bound(all.begin(), all.end(), a[i].r) - all.begin();
    while (t < a[i].r) {
      t++;
      sum[t] = (sum[t - 1] + dp[t]) % mod;
    }
    (dp[a[i].r] += (sum[a[i].r - 1] - sum[a[i].l - 1]) % mod) %= mod;
    sum[a[i].r] = (sum[a[i].r - 1] + dp[a[i].r]) % mod;
  }
  cout << (dp[all.size()] % mod + mod) % mod << endl;
  return 0;
}
