#include <bits/stdc++.h>
using namespace std;
struct Route {
  int start, finish;
};
bool operator<(const Route &a, const Route &b) { return a.finish < b.finish; }
static int mod = 1000000007;
static int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; }
static int sub(int a, int b) { return a - b >= 0 ? a - b : a - b + mod; }
int main() {
  int N, M;
  cin >> N >> M;
  vector<Route> R(M);
  for (int i = 0; i < int(M); ++i) cin >> R[i].start >> R[i].finish;
  int P = 0;
  {
    map<int, int> m;
    m[0] = m[N] = 0;
    for (__typeof((R).begin()) it = (R).begin(); it != (R).end(); ++it)
      m[it->start] = m[it->finish] = 0;
    for (__typeof((m).begin()) it = (m).begin(); it != (m).end(); ++it)
      it->second = P++;
    for (__typeof((R).begin()) it = (R).begin(); it != (R).end(); ++it)
      it->start = m[it->start], it->finish = m[it->finish];
  }
  sort(R.begin(), R.end());
  vector<int> ways(P);
  vector<int> sum(P + 1);
  ways[0] = 1;
  int r = 0;
  for (int p = 0; p < int(P); ++p) {
    while (r < (int((R).size())) && R[r].finish == p) {
      ways[p] = add(ways[p], sub(sum[p], sum[R[r].start]));
      ++r;
    }
    sum[p + 1] = add(sum[p], ways[p]);
  }
  cout << ways[P - 1] << endl;
}
