#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
struct node {
  int s, e;
  bool operator<(const node &nd) const { return e < nd.e; }
};
node nd[100005];
int s[200005], a[200005];
set<int> st;
set<int>::iterator its;
map<int, int> mm;
map<int, int>::iterator itm;
int main() {
  int i, j, m, n, up, pos;
  int t;
  while (scanf("%d%d", &n, &m) == 2) {
    if (m == 0) {
      puts("0");
      continue;
    }
    st.clear();
    mm.clear();
    for (i = 0; i < m; i++) {
      scanf("%d%d", &nd[i].s, &nd[i].e);
      st.insert(nd[i].s);
      st.insert(nd[i].e);
    }
    st.insert(0);
    st.insert(n);
    for (its = st.begin(), i = 0; its != st.end(); i++, its++) {
      mm.insert(pair<int, int>(*its, i));
    }
    up = i - 1;
    for (i = 0; i < m; i++) {
      itm = mm.find(nd[i].s);
      nd[i].s = itm->second;
      itm = mm.find(nd[i].e);
      nd[i].e = itm->second;
    }
    sort(nd, nd + m);
    memset(a, 0, sizeof(a));
    memset(s, 0, sizeof(s));
    a[0] = 1;
    s[0] = 1;
    pos = -1;
    for (i = 0; i < m; i++) {
      if (nd[i].e - 1 != pos) {
        for (j = pos + 2; j < nd[i].e; j++) {
          s[j] = s[j - 1];
          a[j] = 0;
        }
        pos = nd[i].e - 1;
      }
      if (nd[i].s == 0)
        t = s[pos];
      else
        t = (s[pos] - s[nd[i].s - 1]) % MOD;
      a[nd[i].e] = (a[nd[i].e] + t) % MOD;
      s[nd[i].e] = (s[pos] + a[nd[i].e]) % MOD;
    }
    if (a[up] < 0) a[up] += MOD;
    printf("%d\n", a[up]);
  }
}
