#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
vector<pair<long long, long long> > stop;
vector<long long> crd;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  return a.second < b.second;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, i, s, f, firststop, stopid = 0, mp, ans;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> s >> f;
    stop.push_back({s, f});
    crd.push_back(s);
    crd.push_back(f);
  }
  crd.push_back(0);
  crd.push_back(n);
  sort(stop.begin(), stop.end(), comp);
  sort(crd.begin(), crd.end());
  crd.erase(unique(crd.begin(), crd.end()), crd.end());
  for (i = 0; i < stop.size(); i++) {
    stop[i].first =
        lower_bound(crd.begin(), crd.end(), stop[i].first) - crd.begin();
    stop[i].second =
        lower_bound(crd.begin(), crd.end(), stop[i].second) - crd.begin();
  }
  vector<long long> dp(crd.size() + 7, 0), p(crd.size() + 7, 0);
  dp[0] = 1;
  p[0] = 1;
  for (i = 1; i < crd.size() && stopid < m; i++) {
    while (i == stop[stopid].second) {
      firststop = stop[stopid].first;
      if (firststop == 0)
        mp = 0;
      else
        mp = p[firststop - 1];
      dp[i] += (p[i - 1] - mp);
      dp[i] %= MOD;
      stopid++;
    }
    p[i] = (p[i - 1] + dp[i]) % MOD;
  }
  ans = dp[crd.size() - 1];
  if (ans < 0) ans += MOD;
  cout << ans;
}
