#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r;
} a[100001];
int n, m, t;
int p[100001];
int b[2 * 100001];
long long f[2 * 100001], s[2 * 100001];
bool cmp(node x, node y) { return (x.r < y.r); }
void init() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d %d", &a[i].l, &a[i].r);
  sort(a + 1, a + 1 + m, cmp);
  t = 1;
  b[1] = 0;
  for (int i = 1; i <= m; i++) {
    if (a[i].r > b[t]) {
      t++;
      b[t] = a[i].r;
    }
    p[i] = t;
  }
}
int get(int i) {
  int v = 0;
  int x = a[i].l;
  int l = 0, r = p[i];
  while (l <= r) {
    int tm = (l + r) / 2;
    if (b[tm] < x) {
      v = tm;
      l = tm + 1;
    } else
      r = tm - 1;
  }
  return v;
}
void solve() {
  f[1] = 1;
  s[1] = 1;
  for (int i = 1; i <= m; i++) {
    int k = p[i];
    f[k] = (f[k] + 1000000007 + s[k - 1] - s[get(i)]) % 1000000007;
    s[k] = (s[k - 1] + f[k]) % 1000000007;
  }
  if (b[t] == n)
    printf("%I64d\n", f[t]);
  else
    printf("0\n");
}
int main() {
  init();
  solve();
  return 0;
}
