#include <bits/stdc++.h>
const double PI = atan(1) * 4;
using namespace std;
vector<pair<long long, long long>> vec;
int n, m;
long long dp[212345];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  vec.resize(m);
  set<long long> s;
  for (int i = 0; i < m; i++) {
    cin >> vec[i].first >> vec[i].second;
    s.insert(vec[i].first);
    s.insert(vec[i].second);
  }
  s.insert(0);
  s.insert(n);
  map<long long, long long> comp;
  long long cnt = 0;
  for (auto i : s) {
    if (comp.find(i) == comp.end()) {
      comp[i] = cnt;
      cnt++;
    }
  }
  for (auto& i : vec) {
    i.first = comp[i.first];
    i.second = comp[i.second];
  }
  n = comp[n];
  sort(vec.begin(), vec.end(),
       [](pair<long long, long long> a, pair<long long, long long> b) {
         if (a.second != b.second) return a.second < b.second;
         return a.first > b.first;
       });
  dp[n] = 1;
  long long cur = 0;
  long long index = m - 1;
  priority_queue<pair<long long, long long>> pq;
  for (int i = n - 1; i >= 0; i--) {
    while (index >= 0 && vec[index].second > i) {
      cur += dp[vec[index].second];
      cur %= 1000000007;
      pq.push({vec[index].first, dp[vec[index].second]});
      index--;
    }
    dp[i] = cur % 1000000007;
    while (pq.size() && pq.top().first >= i) {
      cur -= pq.top().second;
      cur %= 1000000007;
      cur += 1000000007;
      cur %= 1000000007;
      pq.pop();
    }
  }
  cout << dp[0];
  return 0;
}
