#include <bits/stdc++.h>
using namespace std;
long long dp[200020];
long long acc_dp[200020];
vector<int> bus[200020];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> compression;
  compression.push_back(-1);
  compression.push_back(0);
  compression.push_back(n);
  vector<pair<int, int> > edges(m);
  for (int i = 0; i < m; i++) {
    cin >> edges[i].first >> edges[i].second;
    compression.push_back(edges[i].first);
    compression.push_back(edges[i].second);
  }
  sort(compression.begin(), compression.end());
  compression.erase(unique(compression.begin(), compression.end()),
                    compression.end());
  for (int i = 0; i < m; i++) {
    int start =
        lower_bound(compression.begin(), compression.end(), edges[i].first) -
        compression.begin();
    int end =
        lower_bound(compression.begin(), compression.end(), edges[i].second) -
        compression.begin();
    bus[end].push_back(start);
  }
  int home = lower_bound(compression.begin(), compression.end(), 0) -
             compression.begin();
  int school = lower_bound(compression.begin(), compression.end(), n) -
               compression.begin();
  dp[home] = 1;
  acc_dp[home] = 1;
  for (int pos = home + 1; pos <= school; pos++) {
    for (auto prev : bus[pos]) {
      dp[pos] = dp[pos] + acc_dp[pos - 1] - acc_dp[prev - 1];
      dp[pos] = (dp[pos] % 1000000007 + 1000000007) % 1000000007;
    }
    acc_dp[pos] = (dp[pos] + acc_dp[pos - 1]) % 1000000007;
  }
  cout << dp[school] << '\n';
  return 0;
}
