#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> p[m];
  vector<int> v;
  v.push_back(-1);
  v.push_back(0);
  v.push_back(n);
  for (int i = 0; i < m; i++) {
    cin >> p[i].first;
    cin >> p[i].second;
    v.push_back(p[i].first);
    v.push_back(p[i].second);
  }
  sort(v.begin(), v.end());
  map<int, int> mp;
  int k = 0;
  for (int i = 1; i < (int)v.size(); i++) {
    if (v[i] == v[i - 1]) continue;
    mp[v[i]] = k++;
  }
  vector<pair<int, int> > vp;
  for (int i = 0; i < m; i++) {
    vp.push_back(make_pair(mp[p[i].second], mp[p[i].first]));
  }
  sort(vp.begin(), vp.end());
  for (int i = 0; i < m; i++) {
  }
  long long dp[mp[n] + 1];
  long long pre[mp[n] + 1];
  for (int i = 0; i < mp[n] + 1; i++) {
    dp[i] = 0;
    pre[i] = 0;
  }
  dp[0] = 1;
  pre[0] = 1;
  int lastvisit = 0;
  for (int i = 0; i < m; i++) {
    int end = vp[i].first;
    int start = vp[i].second;
    while (lastvisit != end) {
      pre[lastvisit + 1] = pre[lastvisit];
      lastvisit++;
    }
    if (start > 0) {
      dp[end] = (dp[end] +
                 (pre[end - 1] - pre[start - 1] + 1000000007) % 1000000007) %
                1000000007;
      pre[end] = (pre[end] +
                  (pre[end - 1] - pre[start - 1] + 1000000007) % 1000000007) %
                 1000000007;
    } else {
      dp[end] = (dp[end] + pre[end - 1]) % 1000000007;
      pre[end] = (pre[end] + pre[end - 1]) % 1000000007;
    }
  }
  cout << dp[mp[n]];
}
