#include <bits/stdc++.h>
using namespace std;
const int vc = 1000000007;
const int maxm = 100002;
int first, last, ts, mid, d[maxm << 1], n, m, i, a1[maxm], a2[maxm],
    c[maxm << 1], key, star[(maxm << 1) + 1], ke[maxm << 2], j;
long long res[maxm << 1], b[maxm << 1];
bool p;
int search(int n1) {
  first = 0;
  last = ts + 1;
  p = false;
  while (first + 1 < last && p == false) {
    mid = ((first + last) >> 1);
    if (c[mid] < n1)
      first = mid;
    else if (c[mid] > n1)
      last = mid;
    else
      p = true;
  }
  return d[mid];
}
int main() {
  cin >> n >> m;
  ts = 0;
  for (i = 1; i <= m; i++) {
    cin >> a1[i] >> a2[i];
    ts++;
    c[ts] = a1[i];
    ts++;
    c[ts] = a2[i];
  }
  ts++;
  c[ts] = 0;
  sort(c + 1, c + ts + 1);
  key = 0;
  for (i = 1; i <= ts; i++)
    if (i == 1 || c[i] != c[i - 1]) {
      key++;
      d[i] = key;
    } else
      d[i] = key;
  res[1] = 1;
  b[1] = 1;
  b[0] = 0;
  res[0] = 0;
  memset(star, 0, sizeof(star));
  for (i = 1; i <= m; i++) {
    a1[i] = search(a1[i]);
    a2[i] = search(a2[i]);
    star[a2[i]]++;
  }
  for (i = 2; i <= key; i++) star[i] += star[i - 1];
  star[key + 1] = star[key];
  for (i = 1; i <= m; i++) {
    ke[star[a2[i]]] = i;
    star[a2[i]]--;
  }
  if (n == c[ts]) {
    for (i = 2; i <= key; i++) {
      res[i] = 0;
      for (j = star[i] + 1; j <= star[i + 1]; j++)
        res[i] = (res[i] + b[i - 1] - b[a1[ke[j]] - 1] + vc) % vc;
      b[i] = (b[i - 1] + res[i]) % vc;
    }
    cout << res[key];
  } else
    cout << 0;
}
