#include <bits/stdc++.h>
using namespace std;
pair<int, int> Avt[1000000];
map<int, vector<int> > ToGo;
map<int, int> Answ;
int t[1000000];
set<int> Seconds;
set<int> place;
int moda = 1000000007;
bool cmp(pair<int, int> x1, pair<int, int> x2) { return x1.second < x2.second; }
int N = 131072;
int get(int l, int r) {
  l += N;
  r += N;
  int answ = 0;
  while (r >= l) {
    if (l % 2 == 1) {
      answ = (answ + t[l]) % moda;
      l++;
    }
    if (r % 2 == 0) {
      answ = (answ + t[r]) % moda;
      r--;
    }
    l /= 2;
    r /= 2;
  }
  return answ;
}
void add(int idx, int val) {
  idx += N;
  int answ = 0;
  while (idx >= 1) {
    t[idx] = (t[idx] + val) % moda;
    idx /= 2;
  }
}
map<int, int> LargeToS;
int SmalToL[1000000];
int main() {
  int n;
  int m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &Avt[i].first, &Avt[i].second);
    if (Avt[i].first < n && Avt[i].second >= n) {
      Avt[i].second = n;
    }
    ToGo[Avt[i].second].push_back(Avt[i].first);
    Seconds.insert(Avt[i].second);
  }
  int idx = 0;
  Seconds.insert(0);
  for (set<int>::iterator it = Seconds.begin(); it != Seconds.end(); it++) {
    LargeToS[*it] = idx;
    SmalToL[idx] = *it;
    idx++;
  }
  sort(Avt, Avt + m, cmp);
  ;
  add(0, 1);
  set<int>::iterator it = Seconds.begin();
  it++;
  int sz = Seconds.size();
  for (int i = 0; i < sz - 1; i++) {
    int cur = *it;
    it++;
    for (int j = 0; j < ToGo[cur].size(); j++) {
      int from = ToGo[cur][j];
      int fromNorm = *Seconds.lower_bound(from);
      int answ = 0;
      answ = (answ + get(LargeToS[fromNorm], LargeToS[cur] - 1)) % moda;
      add(LargeToS[cur], answ);
    }
  }
  if (Seconds.find(n) == Seconds.end()) {
    printf("0\n");
  } else
    printf("%d\n", get(sz - 1, sz - 1));
}
