#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
bool comp(const pair<int, int> &p1, const pair<int, int> &p2) {
  if (p1.second == p2.second) return p1.first < p2.first;
  return p1.second < p2.second;
}
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > interval;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    interval.push_back({l, r});
  }
  sort(interval.begin(), interval.end(), comp);
  vector<long long> pre;
  pre.push_back(1);
  vector<int> rights;
  rights.push_back(0);
  long long res = 0;
  for (int i = 0; i < m; i++) {
    int l = interval[i].first;
    int r = interval[i].second;
    int j = lower_bound(rights.begin(), rights.end(), l) - rights.begin();
    int k = lower_bound(rights.begin(), rights.end(), r) - rights.begin() - 1;
    if (j == rights.size()) continue;
    long long ans = (pre[k] % mod) - ((j ? pre[j - 1] : 0) % mod);
    ans %= mod;
    ans += mod;
    ans %= mod;
    if (r == n) {
      res += ans;
      res %= mod;
    } else {
      rights.push_back(r);
      pre.push_back((pre.back() + ans) % mod);
    }
  }
  cout << res << endl;
  return 0;
}
